diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-09-28 23:57:15 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-20 22:35:43 +0200 |
commit | 3d82d5de0425045a745ab6e8b8a7d0e7f804008d (patch) | |
tree | b675a39a52a3a235ff7379282789893ec15b1c93 | |
parent | f8434575357435242114a6f9912c13eb0588149f (diff) | |
download | sparse-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.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -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: |