[PATCH] D49955: [Dominators] Make slow walks shorter

Jakub Kuderski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 28 01:13:39 PDT 2018


kuhar created this revision.
kuhar added reviewers: brzycki, asbirlea, chandlerc, NutshellySima.
Herald added subscribers: dexonsmith, mehdi_amini.
Herald added a reviewer: grosser.

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


Repository:
  rL LLVM

https://reviews.llvm.org/D49955

Files:
  include/llvm/Support/GenericDomTree.h


Index: include/llvm/Support/GenericDomTree.h
===================================================================
--- include/llvm/Support/GenericDomTree.h
+++ include/llvm/Support/GenericDomTree.h
@@ -853,10 +853,15 @@
     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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49955.157839.patch
Type: text/x-patch
Size: 838 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180728/ad582b51/attachment.bin>


More information about the llvm-commits mailing list