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

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 07:02:21 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);
+    if (!isa<VPIRValue>(ResumeFromVectorLoop)) {
+      ResumeFromVectorLoop = MiddleBuilder.createNaryOp(
+          VPInstruction::ExtractLastPart, ResumeFromVectorLoop);
+      ResumeFromVectorLoop = MiddleBuilder.createNaryOp(
+          VPInstruction::ExtractLastLane, ResumeFromVectorLoop);
+    }
     auto *ResumePhiR = ScalarPHBuilder.createScalarPhi(
-        {VectorPhiR, VectorPhiR->getOperand(0)}, VectorPhiR->getDebugLoc());
+        {ResumeFromVectorLoop, VectorPhiR->getOperand(0)},
----------------
david-arm wrote:

Instead of calling `VectorPhiR->getOperand(0)` can we call `VectorPhiR->getStarValue()` if the helper function exists?

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


More information about the llvm-commits mailing list