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

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

 



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

diff --git a/simplify.c b/simplify.c
index f8a0ba726561..187d4fc0c9ab 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1360,9 +1360,17 @@ static int simplify_associative_binop(struct instruction *insn)
 
 static int simplify_add(struct instruction *insn)
 {
+	pseudo_t src1 = insn->src1;
 	pseudo_t src2 = insn->src2;
 	struct instruction *def;
 
+	switch (DEF_OPCODE(def, src1)) {
+	case OP_NEG:				// (-x + y) --> (y - x)
+		switch_pseudo(insn, &insn->src1, insn, &insn->src2);
+		insn->opcode = OP_SUB;
+		return replace_pseudo(insn, &insn->src2, def->src);
+	}
+
 	switch (DEF_OPCODE(def, src2)) {
 	case OP_NEG:				// (x + -y) --> (x - y)
 		insn->opcode = OP_SUB;
diff --git a/validation/optim/simplify-neg-add.c b/validation/optim/simplify-neg-add.c
index 66a820f28069..6223b4f98f3b 100644
--- a/validation/optim/simplify-neg-add.c
+++ b/validation/optim/simplify-neg-add.c
@@ -3,7 +3,6 @@ int neg_add(int x, int y) { return -x + y; }
 /*
  * check-name: simplify-neg-add
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-contains: sub\\..*%arg2, %arg1
-- 
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