diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-08 01:00:40 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-24 22:57:40 +0200 |
commit | 851d925ad7aad00f52a9386374752fd2246d2464 (patch) | |
tree | edc5dd595bf9bb9228741e4ea44693119afdfc32 | |
parent | cea6a6faf6f794d77ffcde5a3f9ae2e43d2341fa (diff) | |
download | sparse-851d925ad7aad00f52a9386374752fd2246d2464.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-neg-add-cte.c | 1 |
2 files changed, 7 insertions, 1 deletions
@@ -1468,6 +1468,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 4e425096..a02c474f 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 |