aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-08-18 18:43:38 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-08-22 09:26:18 +0200
commit3d30b78ec7efa501ad3ea4c5f077ef653ed5b231 (patch)
tree0a0d1b722f8473f3c73b94cd50f537de81baa42e
parentcb4bed63e19e64d62364337cca20285f782ac6fd (diff)
downloadsparse-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.c2
-rw-r--r--validation/optim/shl-and1.c1
2 files changed, 2 insertions, 1 deletions
diff --git a/simplify.c b/simplify.c
index 54ee9421..b814a23e 100644
--- a/simplify.c
+++ b/simplify.c
@@ -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$