[llvm] [VPlan] Materialize VectorTripCount in narrowInterleaveGroups. (PR #182146)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 2 08:53:26 PST 2026
================
@@ -9363,12 +9363,28 @@ static void fixScalarResumeValuesFromBypass(BasicBlock *BypassBlock, Loop *L,
// Fix induction resume values from the additional bypass block.
IRBuilder<> BypassBuilder(BypassBlock, BypassBlock->getFirstInsertionPt());
for (const auto &[IVPhi, II] : LVL.getInductionVars()) {
- auto *Inc = cast<PHINode>(IVPhi->getIncomingValueForBlock(PH));
Value *V = createInductionAdditionalBypassValues(
IVPhi, II, BypassBuilder, ExpandedSCEVs, MainVectorTripCount,
LVL.getPrimaryInduction());
// TODO: Directly add as extra operand to the VPResumePHI recipe.
- Inc->setIncomingValueForBlock(BypassBlock, V);
+ if (auto *Inc = dyn_cast<PHINode>(IVPhi->getIncomingValueForBlock(PH))) {
+ Inc->setIncomingValueForBlock(BypassBlock, V);
+ } else {
+ // If the resume value in the scalar preheader was simplified (e.g., when
+ // narrowInterleaveGroups optimized away the resume PHIs), create a new
+ // PHI to merge the bypass value with the original value.
+ Value *OrigVal = IVPhi->getIncomingValueForBlock(PH);
+ PHINode *NewPhi =
+ PHINode::Create(IVPhi->getType(), pred_size(PH), "bc.resume.val",
+ PH->getFirstNonPHIIt());
+ for (auto *Pred : predecessors(PH)) {
+ if (Pred == BypassBlock)
+ NewPhi->addIncoming(V, Pred);
+ else
+ NewPhi->addIncoming(OrigVal, Pred);
+ }
+ IVPhi->setIncomingValueForBlock(PH, NewPhi);
+ }
----------------
fhahn wrote:
Yes, unfortunately there is no way around it; with the transform applied, there will be no scalar epilogue to execute in some cases after epilogue vectorization. The VPlan for the epilouge vector loop is executed separately, so we will remove the dead phis in the scalar preheader, but after connecting to the main plan, there's an edge from the main vector loop's runtime checks to the scalar preheader, for which we need to account for here.
Will share some patches soon to more more connection logic to VPlan, but handling this case here requires full connection.
https://github.com/llvm/llvm-project/pull/182146
More information about the llvm-commits
mailing list