diff mbox

[03/10] simplify 'x & ~0' to 'x'

Message ID 20180626060002.35753-4-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Luc Van Oostenryck June 26, 2018, 5:59 a.m. UTC
This is another simple identity with the potential to trigger
more simplifications.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c                       | 2 ++
 validation/optim/bits-not-zero.c | 7 +++++++
 2 files changed, 9 insertions(+)
diff mbox

Patch

diff --git a/simplify.c b/simplify.c
index 25e2a41c1..09cbe16dc 100644
--- a/simplify.c
+++ b/simplify.c
@@ -668,6 +668,8 @@  static int simplify_constant_rightside(struct instruction *insn)
 	case OP_AND:
 		if (!value)
 			return replace_with_pseudo(insn, insn->src2);
+		if ((value & bits) == bits)
+			return replace_with_pseudo(insn, insn->src1);
 		return 0;
 
 	case OP_SET_NE:
diff --git a/validation/optim/bits-not-zero.c b/validation/optim/bits-not-zero.c
index 9872794b1..ce74705e8 100644
--- a/validation/optim/bits-not-zero.c
+++ b/validation/optim/bits-not-zero.c
@@ -1,4 +1,5 @@ 
 int  or_not0(int a) { return a | ~0; }
+int and_not0(int a) { return a & ~0; }
 
 /*
  * check-name: bool-not-zero
@@ -11,5 +12,11 @@  or_not0:
 	ret.32      $0xffffffff
 
 
+and_not0:
+.L2:
+	<entry-point>
+	ret.32      %arg1
+
+
  * check-output-end
  */