aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-09-28 23:57:15 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-10-20 22:35:43 +0200
commit3d82d5de0425045a745ab6e8b8a7d0e7f804008d (patch)
treeb675a39a52a3a235ff7379282789893ec15b1c93
parentf8434575357435242114a6f9912c13eb0588149f (diff)
downloadsparse-3d82d5de0425045a745ab6e8b8a7d0e7f804008d.tar.gz
sub: reorganize handling of OP_{ADD,SUB}s with constant rightside
This is a preparatory step for more interesting changes later. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/simplify.c b/simplify.c
index b14f8840..f837b003 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1101,6 +1101,7 @@ static int simplify_constant_rightside(struct instruction *insn)
long long value = insn->src2->value;
long long sbit = 1ULL << (insn->size - 1);
long long bits = sbit | (sbit - 1);
+ int changed = 0;
switch (insn->opcode) {
case OP_OR:
@@ -1113,20 +1114,21 @@ static int simplify_constant_rightside(struct instruction *insn)
insn->opcode = OP_NOT;
return REPEAT_CSE;
}
- goto case_neutral_zero;
+ /* fallthrough */
+ case_neutral_zero:
+ if (!value)
+ return replace_with_pseudo(insn, insn->src1);
+ return 0;
case OP_SUB:
- if (value) {
- insn->opcode = OP_ADD;
- insn->src2 = eval_unop(OP_NEG, insn->size, insn->src2);
- return REPEAT_CSE;
- }
- /* Fall through */
+ insn->opcode = OP_ADD;
+ insn->src2 = eval_unop(OP_NEG, insn->size, insn->src2);
+ changed = REPEAT_CSE;
+ /* fallthrough */
case OP_ADD:
- case_neutral_zero:
if (!value)
return replace_with_pseudo(insn, insn->src1);
- return 0;
+ return changed;
case OP_ASR:
case OP_SHL:
case OP_LSR: