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:24 +0200 |
commit | 70a22c03f856b3997d2c7dddd761daf0da3e3b1e (patch) | |
tree | b9cc158a5caa1397dac3aa74d34521e883ac7f00 | |
parent | f28372ddc5f19bbed4fbd6cff33bb111a4261ce7 (diff) | |
download | sparse-70a22c03f856b3997d2c7dddd761daf0da3e3b1e.tar.gz |
unop: simplify ~(x + C) --> ~C - x
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 7 | ||||
-rw-r--r-- | validation/optim/simplify-not-add-cte.c | 1 |
2 files changed, 7 insertions, 1 deletions
@@ -1462,6 +1462,13 @@ static int simplify_unop(struct instruction *insn) switch (insn->opcode) { case OP_NOT: 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_NOT, insn->size, def->src2); + use_pseudo(insn, def->src1, &insn->src2); + return replace_pseudo(insn, &insn->src1, src); case OP_NOT: // ~(~x) --> x return replace_with_pseudo(insn, def->src); } diff --git a/validation/optim/simplify-not-add-cte.c b/validation/optim/simplify-not-add-cte.c index cf7fe2f2..6594012b 100644 --- a/validation/optim/simplify-not-add-cte.c +++ b/validation/optim/simplify-not-add-cte.c @@ -5,7 +5,6 @@ int foo(int x) { return ~(x + C) == (~C - x); } /* * check-name: simplify-not-add-cte * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-contains: ret\\..*\\$1 |