[PATCH 15/22] add: simplify (x + -y) --> (x - y)

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

 



Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 simplify.c                          | 16 +++++++++++++++-
 validation/optim/simplify-add-neg.c |  1 -
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/simplify.c b/simplify.c
index fa7e1679d7ac..f8a0ba726561 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1358,6 +1358,20 @@ static int simplify_associative_binop(struct instruction *insn)
 	return REPEAT_CSE;
 }
 
+static int simplify_add(struct instruction *insn)
+{
+	pseudo_t src2 = insn->src2;
+	struct instruction *def;
+
+	switch (DEF_OPCODE(def, src2)) {
+	case OP_NEG:				// (x + -y) --> (x - y)
+		insn->opcode = OP_SUB;
+		return replace_pseudo(insn, &insn->src2, def->src);
+	}
+
+	return 0;
+}
+
 static int simplify_sub(struct instruction *insn)
 {
 	pseudo_t src2 = insn->src2;
@@ -1832,8 +1846,8 @@ int simplify_instruction(struct instruction *insn)
 	}
 
 	switch (insn->opcode) {
+	case OP_ADD: return simplify_add(insn);
 	case OP_SUB: return simplify_sub(insn);
-	case OP_ADD:
 	case OP_MUL:
 	case OP_AND:
 	case OP_OR:
diff --git a/validation/optim/simplify-add-neg.c b/validation/optim/simplify-add-neg.c
index 19b64b096567..c24b8e19e5c3 100644
--- a/validation/optim/simplify-add-neg.c
+++ b/validation/optim/simplify-add-neg.c
@@ -3,7 +3,6 @@ int add_neg(int x, int y) { return x + -y; }
 /*
  * check-name: simplify-add-neg
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-contains: sub\\..*%arg1, %arg2
-- 
2.28.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