[llvm] [VPlan] Optimize resume values of IVs together with other exit values. (PR #174239)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 4 04:28:36 PST 2026


================
@@ -562,12 +562,21 @@ static void addInitialSkeleton(VPlan &Plan, Type *InductionTy, DebugLoc IVDL,
 
   createExtractsForLiveOuts(Plan, MiddleVPBB);
 
+  VPBuilder MiddleBuilder(MiddleVPBB, MiddleVPBB->getFirstNonPhi());
   VPBuilder ScalarPHBuilder(ScalarPH);
   for (const auto &[PhiR, ScalarPhiR] : zip_equal(
            drop_begin(HeaderVPBB->phis()), Plan.getScalarHeader()->phis())) {
     auto *VectorPhiR = cast<VPPhi>(&PhiR);
+    VPValue *ResumeFromVectorLoop = VectorPhiR->getOperand(1);
----------------
fhahn wrote:

> How do we know that the second operand of a phi in a vector loop is the resume value used in the middle block? Is this because we're assuming the second operand is always the PHI update and by definition the resume value must always be the update? If so, perhaps worth adding a comment explaining what's going on here to make life easier for the reader?

This is guaranteed by construction (checked in the verifier that the second predecessor of the header is the latch).

We are generating the extracts/phis to resume the scalar loop, which should start at the update from the vector loop.

Added a comment at the outset, hope that clarifies.

> Also is operand 1 is the backedge value do we have a helper function for that we can call? It makes it a bit more readable, i.e. VectorPhiR->getBackedgeValue()

Not for VPPhi unfortuantely, because that's still a generic phi class. Updated to name it BackegeVal.

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


More information about the llvm-commits mailing list