[PATCH] D60356: Accelerate isPotentiallyReachable when a DominatorTree is available.

Nick Lewycky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 5 20:39:36 PDT 2019


nicholas created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

When we show that our stop block is not dominated by the current block, we don't need to visit any of the other dominated blocks except to visit their successors. Efficiently add those transitive successors to the worklist.

      

When both a dominator tree is available and we're in a loop, prefer to jump to the exit blocks of a loop. We could fuse the two by visiting only the non-dominated transitive successors of the loop, but it would have the same effect as simply adding the loop blocks to the worklist and going through the check again. I don't think the savings of redundant checks is worth the complexity, at worst we might have one extra call to DomTree::dominates per loop exit block.

      

In one sense there's no functionality change here, but isPotentiallyReachable now does more work per loop iteration which means that it may complete successfully instead of running into the block limit and giving up.


https://reviews.llvm.org/D60356

Files:
  llvm/lib/Analysis/CFG.cpp


Index: llvm/lib/Analysis/CFG.cpp
===================================================================
--- llvm/lib/Analysis/CFG.cpp
+++ llvm/lib/Analysis/CFG.cpp
@@ -147,6 +147,8 @@
 
   const Loop *StopLoop = LI ? getOutermostLoop(LI, StopBB) : nullptr;
 
+  const DomTreeNode *StopNode = DT ? DT->getNode(StopBB) : nullptr;
+
   // Limit the number of blocks we visit. The goal is to avoid run-away compile
   // times on large CFGs without hampering sensible code. Arbitrarily chosen.
   unsigned Limit = 32;
@@ -159,7 +161,9 @@
       return true;
     if (ExclusionSet && ExclusionSet->count(BB))
       continue;
-    if (DT && DT->dominates(BB, StopBB))
+
+    DomTreeNode *DTN = StopNode ? DT->getNode(BB) : nullptr;
+    if (StopNode && DTN && DT->dominates(DTN, StopNode))
       return true;
 
     const Loop *Outer = nullptr;
@@ -186,6 +190,14 @@
       // any of these blocks, we can skip directly to the exits of the loop,
       // ignoring any other blocks inside the loop body.
       Outer->getExitBlocks(Worklist);
+    } else if (DTN) {
+      // The dominance check effectively visited all blocks dominated by BB.
+      // Skip over the descendants of the DomTreeNode to visit their successors.
+      for (auto I = df_begin(DTN), E = df_end(DTN); I != E; ++I) {
+        for (auto Succ : successors(I->getBlock()))
+          if (!DT->dominates(DTN, DT->getNode(Succ)))
+            Worklist.push_back(Succ);
+      }
     } else {
       Worklist.append(succ_begin(BB), succ_end(BB));
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60356.194001.patch
Type: text/x-patch
Size: 1516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190406/d09219a4/attachment.bin>


More information about the llvm-commits mailing list