diff mbox series

[7/9] simplify (x | M) {==,!=} C

Message ID 20210310214950.84192-8-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series simplify CMP(AND(x,M), C) and CMP(OR(x,M), C) | expand

Commit Message

Luc Van Oostenryck March 10, 2021, 9:49 p.m. UTC
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c                  | 15 +++++++++++++++
 validation/optim/cmpe-or0.c |  1 -
 2 files changed, 15 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/simplify.c b/simplify.c
index b46e08c3b79a..865fadfb590e 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1311,6 +1311,21 @@  static int simplify_compare_constant(struct instruction *insn, long long value)
 			break;
 		}
 		break;
+	case OP_OR:
+		if (!constant(def->src2))
+			break;
+		bits = def->src2->value;
+		switch (insn->opcode) {
+		case OP_SET_EQ:
+			if ((value & bits) != bits)
+				return replace_with_value(insn, 0);
+			break;
+		case OP_SET_NE:
+			if ((value & bits) != bits)
+				return replace_with_value(insn, 1);
+			break;
+		}
+		break;
 	case OP_SEXT:				// sext(x) cmp C --> x cmp trunc(C)
 		osize = def->orig_type->bit_size;
 		if (is_signed_constant(value, osize, size)) {
diff --git a/validation/optim/cmpe-or0.c b/validation/optim/cmpe-or0.c
index bef2316120f7..2e89d611117d 100644
--- a/validation/optim/cmpe-or0.c
+++ b/validation/optim/cmpe-or0.c
@@ -4,7 +4,6 @@  int cmp_ne(int a) { return ((a | 1) == 0) + 1; }
 /*
  * check-name: cmpe-or0
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-returns: 1