Add an helper to replace a binop OP(a, b) and taking care to drop the usage of the previous operands. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- simplify.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/simplify.c b/simplify.c index 24b3dcb52428..046bf02c6d36 100644 --- a/simplify.c +++ b/simplify.c @@ -497,6 +497,23 @@ static inline int replace_binop_value(struct instruction *insn, int op, long lon return REPEAT_CSE; } +/// +// replace binop's opcode and values +// @insn: the instruction to be replaced +// @op: the instruction's new opcode +// @return: REPEAT_CSE +static inline int replace_binop(struct instruction *insn, int op, pseudo_t *pa, pseudo_t a, pseudo_t *pb, pseudo_t b) +{ + pseudo_t olda = *pa; + pseudo_t oldb = *pb; + insn->opcode = op; + use_pseudo(insn, a, pa); + use_pseudo(insn, b, pb); + remove_usage(olda, pa); + remove_usage(oldb, pb); + return REPEAT_CSE; +} + /// // replace the opcode of an instruction // @return: REPEAT_CSE -- 2.29.2