[llvm] [LV] Simplify and unify resume value handling for epilogue vec. (PR #185969)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 13 04:53:48 PDT 2026
================
@@ -9076,14 +8969,25 @@ static void preparePlanForMainVectorLoop(VPlan &MainPlan, VPlan &EpiPlan) {
{}, "vec.epilog.resume.val");
} else {
ResumePhi = cast<VPPhi>(&*ResumePhiIter);
- if (MainScalarPH->begin() == MainScalarPH->end())
- ResumePhi->moveBefore(*MainScalarPH, MainScalarPH->end());
- else if (&*MainScalarPH->begin() != ResumePhi)
+ ResumePhi->setName("vec.epilog.resume.val");
+ if (&MainScalarPH->front() != ResumePhi)
ResumePhi->moveBefore(*MainScalarPH, MainScalarPH->begin());
}
- // Add a user to to make sure the resume phi won't get removed.
- VPBuilder(MainScalarPH)
- .createNaryOp(VPInstruction::ResumeForEpilogue, ResumePhi);
+
+ // Create a ResumeForEpilogue for the canonical IV resume as the
+ // first non-phi, to keep it alive for the epilogue.
+ VPBuilder ResumeBuilder(MainScalarPH);
+ ResumeBuilder.createNaryOp(VPInstruction::ResumeForEpilogue, ResumePhi);
+
+ // Collect resume values for epilogue bypass fixup. Create
+ // ResumeForEpilogue for scalar preheader phis to keep them alive.
+ return to_vector(
+ map_range(MainPlan.getScalarHeader()->phis(), [&](VPRecipeBase &R) {
----------------
fhahn wrote:
This uses the scalar header, to only include the resume phi recipes mapping to the header phis; we may add additional scalar phi above for the canonical IV.
> Also I noticed that getScalarPreheader casts to a VPBasicBlock instead of a VPIRBasicBlock? Unrelated refinement, can quickly fix up?
All we need is a `VPBasicBlock` to access the phis, casting to `VPIRBasicBlock` would seem unnecessarily restrictive?
https://github.com/llvm/llvm-project/pull/185969
More information about the llvm-commits
mailing list