aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-09-28 01:06:54 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-10-20 22:35:43 +0200
commit7a6b487222ab164c2501287fb6d3e0add10a3813 (patch)
tree5ad73a6770a0032f1893e85560fecbd72836e93a
parentdbe0117ce6246725eaacc6ed3cb2b2c3ee14d1cc (diff)
downloadsparse-7a6b487222ab164c2501287fb6d3e0add10a3813.tar.gz
sub: simplify x - (y + x) --> -y
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c2
-rw-r--r--validation/optim/simplify-same-subr-add.c1
2 files changed, 2 insertions, 1 deletions
diff --git a/simplify.c b/simplify.c
index 48bf48d2..68ee6ed0 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1399,6 +1399,8 @@ static int simplify_sub(struct instruction *insn)
case OP_ADD:
if (src1 == def->src1) // x - (x + z) --> -z
return replace_with_unop(insn, OP_NEG, def->src2);
+ if (src1 == def->src2) // x - (y + x) --> -y
+ return replace_with_unop(insn, OP_NEG, def->src1);
break;
case OP_NEG: // (x - -y) --> (x + y)
insn->opcode = OP_ADD;
diff --git a/validation/optim/simplify-same-subr-add.c b/validation/optim/simplify-same-subr-add.c
index bafd2643..950c55f6 100644
--- a/validation/optim/simplify-same-subr-add.c
+++ b/validation/optim/simplify-same-subr-add.c
@@ -3,7 +3,6 @@ int subr_add(int x, int y) { return x - (y + x); }
/*
* check-name: simplify-same-subr-add
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-contains: neg\\..* %arg2