[llvm] [VPlan] Account for early-exit dispatch blocks when updating LI. (PR #185618)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 10 08:25:40 PDT 2026


================
@@ -390,22 +390,40 @@ BasicBlock *VPBasicBlock::createEmptyBasicBlock(VPTransformState &State) {
   return NewBB;
 }
 
+/// Determine the parent loop for \p VPBB by checking if it is an exit block
+/// or if all of its successors lead to exit blocks (following single-successor
+/// chains). Returns the innermost loop containing any of the exits if all
+/// paths lead to exits, or \p DefaultLoop otherwise.
+static Loop *getParentLoopForBlock(VPBlockBase *VPBB, VPlan &Plan, LoopInfo &LI,
+                                   Loop *DefaultLoop) {
+  Loop *ParentLoop = nullptr;
+  for (VPBlockBase *Succ : VPBB->getSuccessors()) {
+    while (Succ && !Plan.isExitBlock(Succ))
+      Succ = Succ->getSingleSuccessor();
+    if (!Succ)
+      return DefaultLoop;
+    Loop *L = LI.getLoopFor(cast<VPIRBasicBlock>(Succ)->getIRBasicBlock());
+    if (L && (!ParentLoop || ParentLoop->contains(L)))
+      ParentLoop = L;
+  }
+  return ParentLoop;
+}
+
----------------
david-arm wrote:

I think that `VPBasicBlock::connectToPredecessors` is a bit of a misleading name here, because it's doing more than just connecting to predecessors. It's also connecting to parent loops. Not something to fix in this PR, but maybe I'll follow up with a NFC rename.

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


More information about the llvm-commits mailing list