diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-09-28 01:17:50 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-20 22:35:43 +0200 |
commit | 7635d5d7501c4029f2253d390ae2d2395b0ac56e (patch) | |
tree | da89b1cf2ef0024ca753d980b860cf0e7b1f535c | |
parent | 7a6b487222ab164c2501287fb6d3e0add10a3813 (diff) | |
download | sparse-7635d5d7501c4029f2253d390ae2d2395b0ac56e.tar.gz |
sub: simplify (x - y) + y --> x
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 5 | ||||
-rw-r--r-- | validation/optim/simplify-same-sub-addl.c | 1 |
2 files changed, 5 insertions, 1 deletions
@@ -1369,6 +1369,11 @@ static int simplify_add(struct instruction *insn) switch_pseudo(insn, &insn->src1, insn, &insn->src2); insn->opcode = OP_SUB; return replace_pseudo(insn, &insn->src2, def->src); + + case OP_SUB: + if (def->src2 == src2) // (x - y) + y --> x + return replace_with_pseudo(insn, def->src1); + break; } switch (DEF_OPCODE(def, src2)) { diff --git a/validation/optim/simplify-same-sub-addl.c b/validation/optim/simplify-same-sub-addl.c index 78f21739..56b6fcc2 100644 --- a/validation/optim/simplify-same-sub-addl.c +++ b/validation/optim/simplify-same-sub-addl.c @@ -3,7 +3,6 @@ int foo(int x, int y) { return (x - y) + y; } /* * check-name: simplify-same-sub-addl * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-contains: ret\\..*%arg1 |