diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-09-30 00:36:27 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-24 22:58:26 +0200 |
commit | f96c229c9ae80b40249f3ff46baa035210bbec53 (patch) | |
tree | 0b23abaca31b6721417969f263e8f547c4327d3b | |
parent | 70a22c03f856b3997d2c7dddd761daf0da3e3b1e (diff) | |
download | sparse-f96c229c9ae80b40249f3ff46baa035210bbec53.tar.gz |
unop: simplify ~(C - x) --> x + ~C
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 6 | ||||
-rw-r--r-- | validation/optim/simplify-not-sub-cte.c | 1 |
2 files changed, 6 insertions, 1 deletions
@@ -1471,6 +1471,12 @@ static int simplify_unop(struct instruction *insn) return replace_pseudo(insn, &insn->src1, src); case OP_NOT: // ~(~x) --> x return replace_with_pseudo(insn, def->src); + case OP_SUB: + if (!constant(def->src1)) + break; + insn->opcode = OP_ADD; // ~(C - x) --> x + ~C + insn->src2 = eval_unop(OP_NOT, insn->size, def->src1); + return replace_pseudo(insn, &insn->src1, def->src2); } break; case OP_NEG: diff --git a/validation/optim/simplify-not-sub-cte.c b/validation/optim/simplify-not-sub-cte.c index ec105beb..1ea73ece 100644 --- a/validation/optim/simplify-not-sub-cte.c +++ b/validation/optim/simplify-not-sub-cte.c @@ -5,7 +5,6 @@ int foo(int x) { return ~(C - x) == (x + ~C); } /* * check-name: simplify-not-sub-cte * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-contains: ret\\..*\\$1 |