diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-12 11:56:52 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-22 09:25:34 +0200 |
| commit | 8ef6a1d0cac7fdbf5f0c0f70f5c3a25cc1e88670 (patch) | |
| tree | c0fd4b8e050b83bde8ef113560d7d44371fe0c3d | |
| parent | 4bcb69f986bc4e584cf47c0bafcaa95eafe8e710 (diff) | |
| download | sparse-dev-8ef6a1d0cac7fdbf5f0c0f70f5c3a25cc1e88670.tar.gz | |
simplify OP((x | C), K) when (C & M) == M
In an expression like OP((x | C), K), if the effective mask (M)
corresponding to OP(_, K) is equal to the combined mask (C & M),
then the OR operation is unneeded and can be replaced by M itself,
giving: OP(M, K).
In mathematical terms:
0) ((x | C) & M) = ((x & M) | (C & M))
1) (C & M) = M
2) ((x & M) | (C & M)) = ((x & M) | M) = M
and so OP((x | C), K) -> OP(M, K).
For example, code like:
unsigned int foo(int x)
{
return (x | 7) & 2;
}
is now simplified into:
foo:
ret.32 $2
which previously was not optimized
foo:
or.32 %r2 <- %arg1, $7
and.32 %r3 <- %r2, $2
ret.32 %r3
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
| -rw-r--r-- | simplify.c | 4 | ||||
| -rw-r--r-- | validation/optim/and-or-constant1.c | 1 |
2 files changed, 4 insertions, 1 deletions
@@ -653,6 +653,10 @@ static int simplify_mask_or(struct instruction *insn, unsigned long long mask, s // if (C & M) == 0: OR(x, C) -> x return replace_pseudo(insn, &insn->src1, src1); } + if (nval == mask) { + // if (C & M) == M: OR(x, C) -> M + return replace_pseudo(insn, &insn->src1, value_pseudo(mask)); + } } return 0; } diff --git a/validation/optim/and-or-constant1.c b/validation/optim/and-or-constant1.c index 3f1c9052..49823d5c 100644 --- a/validation/optim/and-or-constant1.c +++ b/validation/optim/and-or-constant1.c @@ -6,7 +6,6 @@ int foo(int x) /* * check-name: or-and-constant1 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-contains: ret\\..*\\$0xfff |
