diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-18 18:43:38 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-22 09:26:18 +0200 |
| commit | 3d30b78ec7efa501ad3ea4c5f077ef653ed5b231 (patch) | |
| tree | 0a0d1b722f8473f3c73b94cd50f537de81baa42e | |
| parent | cb4bed63e19e64d62364337cca20285f782ac6fd (diff) | |
| download | sparse-dev-3d30b78ec7efa501ad3ea4c5f077ef653ed5b231.tar.gz | |
simplify ((x & M) << S) when (M << S) == (-1 << S)
The instructions SHL(AND(x, M), S) can be simplified into SHL(x, S)
if (M << S) == (-1 << S).
For example, code like:
unsigned foo(unsigned x)
{
return (x & 0x000fffff) << 12;
}
is now optimized into:
foo:
shl.32 %r3 <- %arg1, $12
ret.32 %r3
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
| -rw-r--r-- | simplify.c | 2 | ||||
| -rw-r--r-- | validation/optim/shl-and1.c | 1 |
2 files changed, 2 insertions, 1 deletions
@@ -729,6 +729,8 @@ static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long v nmask = omask & mask; if (nmask == 0) return replace_with_pseudo(insn, value_pseudo(0)); + if (nmask == mask) + return replace_pseudo(insn, &insn->src1, def->src1); // do not simplify into ((A << S) & (M << S)) break; case OP_LSR: diff --git a/validation/optim/shl-and1.c b/validation/optim/shl-and1.c index 5f4fdcb1..13a1675b 100644 --- a/validation/optim/shl-and1.c +++ b/validation/optim/shl-and1.c @@ -12,7 +12,6 @@ unsigned shl_and1(unsigned x) /* * check-name: shl-and1 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-contains: ret\\..*\\$0$ |
