[llvm] r338396 - [Dominators] Make slow walks shorter
Jakub Kuderski via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 31 08:53:10 PDT 2018
Author: kuhar
Date: Tue Jul 31 08:53:10 2018
New Revision: 338396
URL: http://llvm.org/viewvc/llvm-project?rev=338396&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/Support/GenericDomTree.h
Modified: llvm/trunk/include/llvm/Support/GenericDomTree.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GenericDomTree.h?rev=338396&r1=338395&r2=338396&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GenericDomTree.h (original)
+++ llvm/trunk/include/llvm/Support/GenericDomTree.h Tue Jul 31 08:53:10 2018
@@ -853,10 +853,15 @@ protected:
assert(isReachableFromEntry(B));
assert(isReachableFromEntry(A));
+ const unsigned ALevel = A->getLevel();
const DomTreeNodeBase<NodeT> *IDom;
- while ((IDom = B->getIDom()) != nullptr && IDom != A && IDom != B)
+
+ // Don't walk nodes above A's subtree. When we reach A's level, we must
+ // either find A or be in some other subtree not dominated by A.
+ while ((IDom = B->getIDom()) != nullptr && IDom->getLevel() >= ALevel)
B = IDom; // Walk up the tree
- return IDom != nullptr;
+
+ return B == A;
}
/// Wipe this tree's state without releasing any resources.
More information about the llvm-commits
mailing list