From 14484216ec060cbf1ec463e86deb1db668142cf2 Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 30 Dec 2015 12:10:28 +0800 Subject: [PATCH] transforms.cfg_simplifier: handle phi and branch_if properly. --- artiq/compiler/transforms/cfg_simplifier.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/artiq/compiler/transforms/cfg_simplifier.py b/artiq/compiler/transforms/cfg_simplifier.py index 913d37a6e..6017212d4 100644 --- a/artiq/compiler/transforms/cfg_simplifier.py +++ b/artiq/compiler/transforms/cfg_simplifier.py @@ -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()