[PATCH 4/9] unop: 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                          | 4 ++++
 validation/optim/simplify-neg-sub.c | 1 -
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/simplify.c b/simplify.c
index 85c8d1d1df1c..fd486172e6e8 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_SUB:		// -(x - y) --> y - x
+			insn->opcode = OP_SUB;
+			use_pseudo(insn, def->src1, &insn->src2);
+			return replace_pseudo(insn, &insn->src1, def->src2);
 		}
 		break;
 	default:
diff --git a/validation/optim/simplify-neg-sub.c b/validation/optim/simplify-neg-sub.c
index b73c9e5e66b4..9a824f09c1db 100644
--- a/validation/optim/simplify-neg-sub.c
+++ b/validation/optim/simplify-neg-sub.c
@@ -3,7 +3,6 @@ int foo(int x, int y) { return -(x - y) == (y - x); }
 /*
  * check-name: simplify-neg-sub
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-contains: ret\\..*\\$1
-- 
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