forked from M-Labs/artiq
1
0
Fork 0

transforms.cfg_simplifier: handle phi and branch_if properly.

This commit is contained in:
whitequark 2015-12-30 12:10:28 +08:00
parent 04b0db1a91
commit 14484216ec
1 changed files with 10 additions and 0 deletions

View File

@ -18,5 +18,15 @@ class CFGSimplifier:
if len(block.instructions) == 1 and \ if len(block.instructions) == 1 and \
isinstance(block.terminator(), ir.Branch): isinstance(block.terminator(), ir.Branch):
successor, = block.successors() 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.replace_all_uses_with(successor)
block.erase() block.erase()