fix: kill old branch in insert_branch()
commit8c24aa51b70cf1fbbb5ff8fbd90f6bdc482d7e2f
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>
Sat, 13 May 2017 19:53:43 +0000 (13 21:53 +0200)
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>
Fri, 19 May 2017 03:27:51 +0000 (19 05:27 +0200)
tree9aaa19e9c91e3a3f54c5ac62847003726d61fa3d
parente35efe330c6ae7d154197c29b127560d569016d0
fix: kill old branch in insert_branch()

insert_branch() is called after an optimization has detected
an opportunity to convert a switch or a conditional branch
into an unconditional branch (for example because the condition
is a constant). It does this by removing the BB's last instruction
and then allocate a new unconditional branch which is added at
the end of the BB. The old instruction is simply discarded.
Since the discarded instruction is one with a condition we must
insure that the associated usage is also removed (for example,
by calling kill_instruction()).

But currently kill_instruction() is called, just after the call
to insert_branch(), only at a single place. The 4 other places where
insert_branch() is called do nothing with the removed instruction
and it's condition's usage. As consequence, instructions that are
dead are not removed since it still wrongly has an user.

Fix this by adding a call to kill_instruction() in insert_branch()
itself (and make the function description more exact).

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
flow.c
linearize.c
validation/kill-insert-branch.c [new file with mode: 0644]