diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2016-12-18 18:13:04 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-20 22:35:43 +0200 |
| commit | 26a8e420cd5b5e45e0d482fc5455e8d4087f7282 (patch) | |
| tree | ba16732050fdd99d0b3d7f1eb9a2c3515bc2df6f /simplify.c | |
| parent | 0c8f2a719d30a42945f4dbcce4b2f906defad2d2 (diff) | |
| download | sparse-dev-26a8e420cd5b5e45e0d482fc5455e8d4087f7282.tar.gz | |
add: simplify (x + -y) --> (x - y)
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'simplify.c')
| -rw-r--r-- | simplify.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -1358,6 +1358,20 @@ static int simplify_associative_binop(struct instruction *insn) return REPEAT_CSE; } +static int simplify_add(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_SUB; + return replace_pseudo(insn, &insn->src2, def->src); + } + + return 0; +} + static int simplify_sub(struct instruction *insn) { pseudo_t src2 = insn->src2; @@ -1832,8 +1846,8 @@ int simplify_instruction(struct instruction *insn) } switch (insn->opcode) { + case OP_ADD: return simplify_add(insn); case OP_SUB: return simplify_sub(insn); - case OP_ADD: case OP_MUL: case OP_AND: case OP_OR: |
