diff mbox series

[5/9] unop: simplify -(~x) --> x + 1

Message ID 20201023163939.58359-6-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series basic unop simplifications | expand

Commit Message

Luc Van Oostenryck Oct. 23, 2020, 4:39 p.m. UTC
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c                          | 4 ++++
 validation/optim/simplify-neg-not.c | 1 -
 2 files changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/simplify.c b/simplify.c
index fd486172e6e8..8f6b821dcf8c 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1478,6 +1478,10 @@  static int simplify_unop(struct instruction *insn)
 			return replace_pseudo(insn, &insn->src1, src);
 		case OP_NEG:		// -(-x) --> x
 			return replace_with_pseudo(insn, def->src);
+		case OP_NOT:
+			insn->opcode = OP_ADD;	// -(~x) --> x + 1
+			insn->src2 = value_pseudo(1);
+			return replace_pseudo(insn, &insn->src1, def->src);
 		case OP_SUB:		// -(x - y) --> y - x
 			insn->opcode = OP_SUB;
 			use_pseudo(insn, def->src1, &insn->src2);
diff --git a/validation/optim/simplify-neg-not.c b/validation/optim/simplify-neg-not.c
index 4bd0abfb0628..e92352cfeeec 100644
--- a/validation/optim/simplify-neg-not.c
+++ b/validation/optim/simplify-neg-not.c
@@ -3,7 +3,6 @@  int foo(int x) { return -(~x) == x + 1; }
 /*
  * check-name: simplify-neg-not
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-contains: ret\\..*\\$1