[PATCH 6/6] simplify ((x & M) << S) when (M << S) == (-1 << S)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 simplify.c                  | 2 ++
 validation/optim/shl-and1.c | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/simplify.c b/simplify.c
index 5c1c98088..1f2ff6e67 100644
--- a/simplify.c
+++ b/simplify.c
@@ -698,6 +698,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 b7876e4e0..f6489cf00 100644
--- a/validation/optim/shl-and1.c
+++ b/validation/optim/shl-and1.c
@@ -11,7 +11,6 @@ unsigned foo(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$
-- 
2.18.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux