Skip to content

Commit

Permalink
transforms.cfg_simplifier: handle phi and branch_if properly.
Browse files Browse the repository at this point in the history
whitequark committed Dec 30, 2015
1 parent 04b0db1 commit 1448421
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions artiq/compiler/transforms/cfg_simplifier.py
Original file line number Diff line number Diff line change
@@ -18,5 +18,15 @@ def process_function(self, func):
if len(block.instructions) == 1 and \
isinstance(block.terminator(), ir.Branch):
successor, = block.successors()

for insn in set(block.uses):
if isinstance(insn, ir.BranchIf) and \
((insn.if_true() == block and insn.if_false() == successor) or
(insn.if_true() == successor and insn.if_false() == block)):
# Our IR doesn't tolerate branch_if %c, %b, %b
insn.replace_with(ir.Branch(successor))
elif isinstance(insn, ir.Phi):
insn.remove_incoming_block(block)

block.replace_all_uses_with(successor)
block.erase()

0 comments on commit 1448421

Please sign in to comment.