diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-26 23:40:41 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-27 17:27:07 +0100 |
commit | 6661a9c4d82042bb65d1ae3bbe7f24cafafdf5e4 (patch) | |
tree | cb3698dc643b70adc569f99f33602d42f5aa25d1 | |
parent | 7e6a070827d2c21c615fb4f57acfe05e669cbf77 (diff) | |
download | sparse-6661a9c4d82042bb65d1ae3bbe7f24cafafdf5e4.tar.gz |
refactor simplify_add() to avoid code duplication
Do some refactoring in simplify_add() to avoid some code
duplication there and better handle generic transforms
that need to be applied on both operands.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 22 |
1 files changed, 9 insertions, 13 deletions
@@ -1620,11 +1620,11 @@ static int simplify_associative_binop(struct instruction *insn) return REPEAT_CSE; } -static int simplify_add(struct instruction *insn) +static int simplify_add_one_side(struct instruction *insn, pseudo_t *p1, pseudo_t *p2) { - pseudo_t src1 = insn->src1; - pseudo_t src2 = insn->src2; struct instruction *def; + pseudo_t src1 = *p1; + pseudo_t src2 = *p2; switch (DEF_OPCODE(def, src1)) { case OP_NEG: // (-x + y) --> (y - x) @@ -1635,19 +1635,15 @@ static int simplify_add(struct instruction *insn) return replace_with_pseudo(insn, def->src1); break; } - - switch (DEF_OPCODE(def, src2)) { - case OP_NEG: // (x + -y) --> (x - y) - return replace_binop(insn, OP_SUB, &insn->src1, src1, &insn->src2, def->src); - case OP_SUB: - if (src1 == def->src2) // x + (y - x) --> y - return replace_with_pseudo(insn, def->src1); - break; - } - return 0; } +static int simplify_add(struct instruction *insn) +{ + return simplify_add_one_side(insn, &insn->src1, &insn->src2) || + simplify_add_one_side(insn, &insn->src2, &insn->src1); +} + static int simplify_sub(struct instruction *insn) { pseudo_t src1 = insn->src1; |