[llvm] [VPlan] Introduce scalar loop header in plan, remove VPLiveOut. (PR #109975)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 27 14:41:45 PDT 2024


================
@@ -8978,15 +8962,25 @@ static void addLiveOutsForFirstOrderRecurrences(
     //     lo = lcssa.phi [s1, scalar.body],
     //                    [vector.recur.extract.for.phi, middle.block]
     //
-    // Extract the resume value and create a new VPLiveOut for it.
+    // Extract the resume value and update the VPIRInstrunction wrapping the
+    // phi in the scalar header block.
     auto *Resume = MiddleBuilder.createNaryOp(VPInstruction::ExtractFromEnd,
                                               {FOR->getBackedgeValue(), OneVPV},
                                               {}, "vector.recur.extract");
     auto *ResumePhiRecipe = ScalarPHBuilder.createNaryOp(
         VPInstruction::ResumePhi, {Resume, FOR->getStartValue()}, {},
         "scalar.recur.init");
     auto *FORPhi = cast<PHINode>(FOR->getUnderlyingInstr());
-    Plan.addLiveOut(FORPhi, ResumePhiRecipe);
+    VPIRInstruction *IRI = nullptr;
+    for (VPRecipeBase &R : *Plan.getScalarHeader()) {
+      IRI = cast<VPIRInstruction>(&R);
+      if (&IRI->getInstruction() == FORPhi) {
+        IRI->addOperand(ResumePhiRecipe);
+        break;
+      }
+      IRI = nullptr;
+    }
+    assert(IRI && "IRI needs to be set, implying it had its operand updated");
 
     // Now update VPIRInstructions modeling LCSSA phis in the exit block.
     // Extract the penultimate value of the recurrence and use it as operand for
----------------
ayalz wrote:

(independent): ok to remove ExitIRI during traversal of ExitUsersToFix below? Better make_early_inc_range?
OTOH, is more than one LCSSA phi expected to have FOR as its operand? If not better `break` as soon as it is found and handled.

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


More information about the llvm-commits mailing list