mmitton opened PR #5851 from branch_folding
to main
:
I have implemented branch folding for constant value conditionals inside the egraph midend. This covers BrIf and BrTable, converting them to Jump instructions and removing edges in the ControlFlowGraph and updating the DominatorTree, detecting unreachable code and removing them as well.
This necessitated having mutable access to the DominatorTree in egraph, so it had to be removed from AliasAnalysis and passed to AliasAnalysis for the functions that needed it. As a side benefit, this cleaned up some lifetimes sprinkled around to have a reference to DominatorTree in AliasAnalysis.
A block is determined to be unreachable if it no longer has any predecessors or has one predecessor and is the head of a loop.
After folding the branch and removing pred/succ to dead code, when a block is processed, a check is made to see if there are parameters to the block and there is one and only one pred to the block. If this is the case, the parameters are detached from the block and aliased to the passed arguments in the BlockCall.
I have chatted briefly with @cfallin while implementing this, and he suggested I create a PR to let people review the changes.
mmitton updated PR #5851 from branch_folding
to main
.
mmitton updated PR #5851 from branch_folding
to main
.
Last updated: Nov 22 2024 at 16:03 UTC