diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-09-29 00:45:30 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-20 22:35:43 +0200 |
commit | d0329076fd9e0228f9586e21406ab2a4babb5c4d (patch) | |
tree | a48accc631bbd1e6cb3b7b10ab33270bd3d69ced | |
parent | c28f68be15dbbdcb6e6ed08fdff2b0aa89a426e9 (diff) | |
download | sparse-d0329076fd9e0228f9586e21406ab2a4babb5c4d.tar.gz |
sub: simplify (C - y) + D --> eval(C+D) - y
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 20 | ||||
-rw-r--r-- | validation/optim/simplify-cte-sub-addl.c | 1 |
2 files changed, 20 insertions, 1 deletions
@@ -1096,6 +1096,24 @@ static int simplify_constant_mask(struct instruction *insn, unsigned long long m return 0; } +static int simplify_const_rightadd(struct instruction *def, struct instruction *insn) +{ + unsigned size = insn->size; + pseudo_t src2 = insn->src2; + + switch (def->opcode) { + case OP_SUB: + if (constant(def->src1)) { // (C - y) + D --> eval(C+D) - y + pseudo_t val = eval_op(OP_ADD, size, def->src1, src2); + insn->opcode = OP_SUB; + use_pseudo(insn, def->src2, &insn->src2); + return replace_pseudo(insn, &insn->src1, val); + } + break; + } + return 0; +} + static int simplify_constant_rightside(struct instruction *insn) { long long value = insn->src2->value; @@ -1128,6 +1146,8 @@ static int simplify_constant_rightside(struct instruction *insn) case OP_ADD: if (!value) return replace_with_pseudo(insn, insn->src1); + if (insn->src1->type == PSEUDO_REG) // (x # y) + z + changed |= simplify_const_rightadd(insn->src1->def, insn); return changed; case OP_ASR: case OP_SHL: diff --git a/validation/optim/simplify-cte-sub-addl.c b/validation/optim/simplify-cte-sub-addl.c index 49e51006..13702963 100644 --- a/validation/optim/simplify-cte-sub-addl.c +++ b/validation/optim/simplify-cte-sub-addl.c @@ -3,7 +3,6 @@ int cte_sub_addl(int x) { return (1 - x) + 1; } /* * check-name: simplify-cte-sub-addl * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-contains: sub\\..*\\$2, %arg1 |