diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2016-12-18 18:26:02 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-20 22:35:43 +0200 |
commit | 0c8f2a719d30a42945f4dbcce4b2f906defad2d2 (patch) | |
tree | 98a75ab3ca75881e980d4423afec1481eb7b5673 | |
parent | d0329076fd9e0228f9586e21406ab2a4babb5c4d (diff) | |
download | sparse-0c8f2a719d30a42945f4dbcce4b2f906defad2d2.tar.gz |
sub: simplify (x - -y) --> (x + y)
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 16 | ||||
-rw-r--r-- | validation/optim/simplify-sub-neg.c | 1 |
2 files changed, 15 insertions, 2 deletions
@@ -1358,6 +1358,20 @@ static int simplify_associative_binop(struct instruction *insn) return REPEAT_CSE; } +static int simplify_sub(struct instruction *insn) +{ + pseudo_t src2 = insn->src2; + struct instruction *def; + + switch (DEF_OPCODE(def, src2)) { + case OP_NEG: // (x - -y) --> (x + y) + insn->opcode = OP_ADD; + return replace_pseudo(insn, &insn->src2, def->src); + } + + return 0; +} + static int simplify_constant_unop(struct instruction *insn) { long long val = insn->src1->value; @@ -1818,8 +1832,8 @@ int simplify_instruction(struct instruction *insn) } switch (insn->opcode) { + case OP_SUB: return simplify_sub(insn); case OP_ADD: - case OP_SUB: case OP_MUL: case OP_AND: case OP_OR: diff --git a/validation/optim/simplify-sub-neg.c b/validation/optim/simplify-sub-neg.c index b6fcc2ba..49be847c 100644 --- a/validation/optim/simplify-sub-neg.c +++ b/validation/optim/simplify-sub-neg.c @@ -3,7 +3,6 @@ int sub_neg(int x, int y) { return x - -y; } /* * check-name: simplify-sub-neg * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-contains: add\\..*%arg., %arg. |