Optimize CFG dominance queries for value elimination
Improves the performance of dominance queries in SCCVN by using dynamic dominator tracking.
This commit optimizes the dominated_by_p_w_unex function, which is frequently used during value elimination in the SCCVN pass. The previous implementation relied on a slow, heuristic walk across the CFG. The new approach dynamically tracks immediate dominators of the executable CFG using an array indexed by RPO number, updated via a Cooper-Harvey-Kennedy nearest-common-ancestor intersection. This significantly speeds up the dominance queries from an arbitrary limit to O(depth of the dominator tree) while removing unsafe handling of back-edges.
In Details
The tree-ssa-sccvn.cc file's dominated_by_p_w_unex function, crucial for value elimination during RPO iteration, was rewritten. It previously used a heuristic walk that was slow and limited. The new implementation introduces vn_exec_idom and update_exec_idom to maintain immediate dominators for the executable portion of the CFG during the RPO walk. This is achieved via a single-pass Cooper-Harvey-Kennedy algorithm on forward edges, with conservative handling of backward edges using whole-CFG dominators. The query complexity drops to O(depth of dominator tree), improving performance on…
- CFG
- Control Flow Graph. A graphical representation of a program's execution flow, where nodes are basic blocks and edges represent control transfers.
- RPO
- Reverse Postorder. A specific ordering of basic blocks in a CFG that is useful for certain compiler analyses and optimizations, such as dominator tree construction.
- SCCVN
- Strongly Connected Components Value Numbering. A compiler optimization pass that identifies and simplifies redundant computations within loops and other strongly connected components of the CFG.
- dominator tree
- A tree structure representing the dominance relationships in a CFG, where a node 'A' dominates node 'B' if every path from the entry node to 'B' must go through 'A'.
- immediate dominator
- In a dominator tree, the dominator of a node that is closest to that node. Every node except the entry node has a unique immediate dominator.
- Cooper-Harvey-Kennedy
- An efficient algorithm for computing immediate dominators in a control flow graph.