diff mbox series

[08/13] simplify SETNE(AND(X,1),0) to AND(X,1)

Message ID 20180804203555.23887-9-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series fix linearize_logical() & simplification | expand

Commit Message

Luc Van Oostenryck Aug. 4, 2018, 8:35 p.m. UTC
Since the OP_SETCC instructions can only return a 0 or a 1,
a compare-not-equal-zero or compare-equal-1 is a no-op
if the operand have been masked with 1.

Remove the no-op comparison (if the size matches).

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c                      | 10 ++++++++++
 validation/optim/mask1-setne0.c |  1 -
 2 files changed, 10 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/simplify.c b/simplify.c
index 839452b00..ae53e7ae7 100644
--- a/simplify.c
+++ b/simplify.c
@@ -713,6 +713,16 @@  static int simplify_seteq_setne(struct instruction *insn, long long value)
 	}
 	opcode = def->opcode;
 	switch (opcode) {
+	case OP_AND:
+		if (inverse)
+			break;
+		if (def->size != insn->size)
+			break;
+		if (def->src2->type != PSEUDO_VAL)
+			break;
+		if (def->src2->value != 1)
+			break;
+		return replace_with_pseudo(insn, old);
 	case OP_FPCMP ... OP_BINCMP_END:
 		// Convert:
 		//	setcc.n	%t <- %a, %b
diff --git a/validation/optim/mask1-setne0.c b/validation/optim/mask1-setne0.c
index 8810189cd..1e599dc80 100644
--- a/validation/optim/mask1-setne0.c
+++ b/validation/optim/mask1-setne0.c
@@ -16,7 +16,6 @@  int foo(struct s x)
 /*
  * check-name: mask1-setne0
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-start
 foo: