[llvm] [VPlan] Introduce scalar loop header in plan, remove VPLiveOut. (PR #109975)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 31 10:09:30 PDT 2024
================
@@ -8790,6 +8787,31 @@ static void addCanonicalIVRecipes(VPlan &Plan, Type *IdxTy, bool HasNUW,
{CanonicalIVIncrement, &Plan.getVectorTripCount()}, DL);
}
+/// Create resume phis in the scalar preheader for first-order recurrences and
+/// reductions and update the VPIRInstructions wrapping the original phis in the
+/// scalar header.
+static void addScalarResumePhis(VPRecipeBuilder &Builder, VPlan &Plan) {
+ for (VPRecipeBase &R : *Plan.getScalarHeader()) {
+ auto *IRI = cast<VPIRInstruction>(&R);
+ if (!isa<PHINode>(IRI->getInstruction()))
+ break;
+
+ VPBuilder ScalarPHBuilder(Plan.getScalarPreheader());
+ auto *VectorR =
+ dyn_cast<VPHeaderPHIRecipe>(Builder.getRecipe(&IRI->getInstruction()));
+ if (isa<VPFirstOrderRecurrencePHIRecipe, VPReductionPHIRecipe>(VectorR)) {
+ StringRef Name = isa<VPFirstOrderRecurrencePHIRecipe>(VectorR)
+ ? "scalar.recur.init"
+ : "bc.merge.rdx";
+ auto *ResumePhiRecipe = ScalarPHBuilder.createNaryOp(
+ VPInstruction::ResumePhi,
+ {VectorR->getBackedgeValue(), VectorR->getStartValue()}, {}, Name);
+
+ IRI->addOperand(ResumePhiRecipe);
+ }
+ }
----------------
fhahn wrote:
Adjusted, thanks!
https://github.com/llvm/llvm-project/pull/109975
More information about the llvm-commits
mailing list