2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 03:08:27 +08:00

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

View File

@ -18,5 +18,15 @@ class CFGSimplifier:
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()