[PATCH 3/9] unop: simplify -(x + C) --> -C - x

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

 



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

diff --git a/simplify.c b/simplify.c
index 2750a90512b8..85c8d1d1df1c 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1469,6 +1469,13 @@ static int simplify_unop(struct instruction *insn)
 		break;
 	case OP_NEG:
 		switch (DEF_OPCODE(def, src)) {
+		case OP_ADD:
+			if (!constant(def->src2))
+				break;
+			insn->opcode = OP_SUB;	// -(x + C) --> (-C - x)
+			src = eval_unop(OP_NEG, insn->size, def->src2);
+			use_pseudo(insn, def->src1, &insn->src2);
+			return replace_pseudo(insn, &insn->src1, src);
 		case OP_NEG:		// -(-x) --> x
 			return replace_with_pseudo(insn, def->src);
 		}
diff --git a/validation/optim/simplify-neg-add-cte.c b/validation/optim/simplify-neg-add-cte.c
index 4e425096a489..a02c474fa25a 100644
--- a/validation/optim/simplify-neg-add-cte.c
+++ b/validation/optim/simplify-neg-add-cte.c
@@ -5,7 +5,6 @@ int foo(int x) { return -(x + C) == (-3 - x); }
 /*
  * check-name: simplify-neg-add-cte
  * 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