Skip to content

Commit 3ae770a

Browse files
committed
[Dominators] Make slow walks shorter
Summary: When DFS numbers are not yet calculated for a dominator tree, we have to walk it up to say whether one node dominates some other. This patch makes the slow walks shorter by only walking until the level of the node we check against is reached. This is because a node cannot possibly dominate something higher in its tree. When running opt with -O3, the patch results in: * 25% fewer loop iterations for `opt` (fullLTO) * 30% fewer loop iterations for sqlite Reviewers: brzycki, asbirlea, chandlerc, NutshellySima, grosser Reviewed By: NutshellySima Subscribers: mehdi_amini, dexonsmith, llvm-commits Differential Revision: https://reviews.llvm.org/D49955 llvm-svn: 338396
1 parent d83beb8 commit 3ae770a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

llvm/include/llvm/Support/GenericDomTree.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,10 +853,15 @@ class DominatorTreeBase {
853853
assert(isReachableFromEntry(B));
854854
assert(isReachableFromEntry(A));
855855

856+
const unsigned ALevel = A->getLevel();
856857
const DomTreeNodeBase<NodeT> *IDom;
857-
while ((IDom = B->getIDom()) != nullptr && IDom != A && IDom != B)
858+
859+
// Don't walk nodes above A's subtree. When we reach A's level, we must
860+
// either find A or be in some other subtree not dominated by A.
861+
while ((IDom = B->getIDom()) != nullptr && IDom->getLevel() >= ALevel)
858862
B = IDom; // Walk up the tree
859-
return IDom != nullptr;
863+
864+
return B == A;
860865
}
861866

862867
/// Wipe this tree's state without releasing any resources.

0 commit comments

Comments
 (0)