insert_branch() changes a switch or a conditional branch into a jump. This is implemented by deleting the old instruction and allocating the new one. This is not needed here since no reference to the old instruction is kept. So, simply reuse the terminating instruction and change it. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- linearize.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/linearize.c b/linearize.c index 2268b0951376..1d85cf2ba208 100644 --- a/linearize.c +++ b/linearize.c @@ -696,18 +696,14 @@ static void set_activeblock(struct entrypoint *ep, struct basic_block *bb) void insert_branch(struct instruction *jmp, struct basic_block *target) { struct basic_block *bb = jmp->bb; - struct instruction *br, *old; struct basic_block *child; - /* Remove the switch */ - old = delete_last_instruction(&bb->insns); - assert(old == jmp); - kill_instruction(old); - - br = alloc_instruction(OP_BR, 0); - br->bb = bb; - br->bb_true = target; - add_instruction(&bb->insns, br); + kill_use(&jmp->cond); + jmp->bb_true = target; + jmp->bb_false = NULL; + jmp->cond = NULL; + jmp->size = 0; + jmp->opcode = OP_BR; FOR_EACH_PTR(bb->children, child) { if (child == target) { -- 2.31.0