[llvm] [CFG] Add shortcut if CycleInfo is available (PR #188928)

Robert Imschweiler via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 27 01:56:59 PDT 2026


================
@@ -235,10 +235,19 @@ static bool isReachableImpl(SmallVectorImpl<BasicBlock *> &Worklist,
     const Cycle *OuterC = nullptr;
     if (CI) {
       OuterC = CI->getTopLevelParentCycle(BB);
+      bool InCycle = OuterC != nullptr;
       if (CyclesWithHoles.count(OuterC))
         OuterC = nullptr;
       else if (StopCycles.contains(OuterC))
         return true;
+      // If BB is not part of a cycle, then it can't reach any block that
+      // dominates it. An exception is if the block is unreachable, as all
+      // reachable blocks dominate an unreachable block.
+      if (!InCycle && DT &&
+          llvm::all_of(StopSet, [&](const BasicBlock *StopBB) {
+            return DT->isReachableFromEntry(BB) && DT->dominates(StopBB, BB);
----------------
ro-i wrote:

`DT->isReachableFromEntry(BB)` should probably be moved out of the loop

https://github.com/llvm/llvm-project/pull/188928


More information about the llvm-commits mailing list