Currently, simplify_unop() can only handle the simplification of -(-x) and ~(~x). Prepare it to handle more cases. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- simplify.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/simplify.c b/simplify.c index 6caf6cbcf918..2750a90512b8 100644 --- a/simplify.c +++ b/simplify.c @@ -1451,21 +1451,27 @@ static int simplify_constant_unop(struct instruction *insn) static int simplify_unop(struct instruction *insn) { + pseudo_t src = insn->src; + if (dead_insn(insn, &insn->src1, NULL, NULL)) return REPEAT_CSE; - if (constant(insn->src1)) + if (constant(src)) return simplify_constant_unop(insn); switch (insn->opcode) { struct instruction *def; case OP_NOT: - if (DEF_OPCODE(def, insn->src) == OP_NOT) + switch (DEF_OPCODE(def, src)) { + case OP_NOT: // ~(~x) --> x return replace_with_pseudo(insn, def->src); + } break; case OP_NEG: - if (DEF_OPCODE(def, insn->src) == OP_NEG) + switch (DEF_OPCODE(def, src)) { + case OP_NEG: // -(-x) --> x return replace_with_pseudo(insn, def->src); + } break; default: return 0; -- 2.28.0