aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-26 23:29:30 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-27 17:27:07 +0100
commit7e6a070827d2c21c615fb4f57acfe05e669cbf77 (patch)
tree908f314e6ea21f35c0e47edd9038893147d15c8a
parent9e6eaf742cb4a66da9f9a15195420e43633c8fe6 (diff)
downloadsparse-7e6a070827d2c21c615fb4f57acfe05e669cbf77.tar.gz
refactor simplify_add() to avoid code duplication (preparation)
Do some refactoring in simplify_add() to prepare the next patch which will avoid some code duplication there. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/simplify.c b/simplify.c
index 046bf02c..82ff1242 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1628,9 +1628,7 @@ static int simplify_add(struct instruction *insn)
switch (DEF_OPCODE(def, src1)) {
case OP_NEG: // (-x + y) --> (y - x)
- switch_pseudo(insn, &insn->src1, insn, &insn->src2);
- insn->opcode = OP_SUB;
- return replace_pseudo(insn, &insn->src2, def->src);
+ return replace_binop(insn, OP_SUB, &insn->src1, src2, &insn->src2, def->src);
case OP_SUB:
if (def->src2 == src2) // (x - y) + y --> x
@@ -1640,8 +1638,7 @@ static int simplify_add(struct instruction *insn)
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 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);