[PATCH v2 15/15] simplify SHL((x & M') | y, S)

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

 



The same simplifications done for LSR can be done for SHL
(with the appropriate mask).

For example, code like:
	int foo(int a, int b)
	{
		return ((a & 0xfff00000) | b) << 12;
	}

is now optimized into:
	foo:
		shl.32      %r5 <- %arg2, $12
		ret.32      %r5

while previously it was:
	foo:
		and.32      %r2 <- %arg1, $0xfff00000
		or.32       %r4 <- %r2, %arg2
		shl.32      %r5 <- %r4, $12
		ret.32      %r5

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 simplify.c                     | 4 ++++
 validation/optim/and-or-shl0.c | 1 -
 validation/optim/and-or-shl1.c | 1 -
 validation/optim/and-or-shl2.c | 1 -
 validation/optim/and-or-shlx.c | 1 -
 5 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/simplify.c b/simplify.c
index 5a802d207..b2018bfc4 100644
--- a/simplify.c
+++ b/simplify.c
@@ -596,6 +596,7 @@ static int simplify_mask_or_and(struct instruction *insn, unsigned long long mas
 // For the @mask (M):
 //	* if OP == AND, @mask M is C
 //	* if OP == LSR, @mask M is (-1 << C)
+//	* if OP == SHL, @mask M is (-1 >> C)
 static int simplify_mask_or(struct instruction *insn, unsigned long long mask, struct instruction *or)
 {
 	pseudo_t src1 = or->src1;
@@ -750,6 +751,9 @@ static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long v
 		if (value >= size)
 			goto zero;
 		switch(DEF_OPCODE(def, pseudo)) {
+		case OP_OR:
+			mask = bits_mask(size - value);
+			return simplify_mask_or(insn, mask, def);
 		case OP_SHL:
 		case_shift_shift:		// also for LSR - LSR
 			if (def == insn)	// cyclic DAG!
diff --git a/validation/optim/and-or-shl0.c b/validation/optim/and-or-shl0.c
index c9914f22c..4850b3262 100644
--- a/validation/optim/and-or-shl0.c
+++ b/validation/optim/and-or-shl0.c
@@ -6,7 +6,6 @@ int foo(int a, int b)
 /*
  * check-name: and-or-shl0
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-excludes: or\\.
diff --git a/validation/optim/and-or-shl1.c b/validation/optim/and-or-shl1.c
index 1c7b104cf..bea222450 100644
--- a/validation/optim/and-or-shl1.c
+++ b/validation/optim/and-or-shl1.c
@@ -6,7 +6,6 @@ int foo(int a, int b)
 /*
  * check-name: and-or-shl1
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-pattern(0): and\\.
diff --git a/validation/optim/and-or-shl2.c b/validation/optim/and-or-shl2.c
index a00993255..f5f62758d 100644
--- a/validation/optim/and-or-shl2.c
+++ b/validation/optim/and-or-shl2.c
@@ -6,7 +6,6 @@ int foo(int x, int y)
 /*
  * check-name: and-or-shl2
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-contains: and\\..*\\$0xfff0f
diff --git a/validation/optim/and-or-shlx.c b/validation/optim/and-or-shlx.c
index b68628006..ec2a2ced4 100644
--- a/validation/optim/and-or-shlx.c
+++ b/validation/optim/and-or-shlx.c
@@ -6,7 +6,6 @@ unsigned int foo(unsigned int x, unsigned int y, unsigned int a)
 /*
  * check-name: and-or-shlx
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-pattern(1): and\\.
-- 
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