[llvm] [VPlan] Create AnyOf and FindIV resume adjustments in the epilogue plan. (PR #227882)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 3 12:34:47 PDT 2026
================
@@ -7433,41 +7431,40 @@ static SmallVector<Instruction *> preparePlanForEpilogueVectorLoop(
});
RecurKind RK = ReductionPhi->getRecurrenceKind();
+ ResumeVPV = Plan.getOrAddLiveIn(ResumeForEpi->getUnderlyingValue());
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK) || IsFindIV) {
- auto *ResumePhi = cast<PHINode>(ResumeV);
VPValue *BypassOp = ResumeForEpi->getOperand(1);
assert((isa<VPIRValue>(BypassOp) ||
VPlanPatternMatch::match(
BypassOp,
m_VPInstruction<Instruction::Freeze>(m_VPValue()))) &&
"expected live-in or Freeze");
- Value *StartV = BypassOp->getUnderlyingValue();
- IRBuilder<> Builder(ResumePhi->getParent(),
- ResumePhi->getParent()->getFirstNonPHIIt());
-
+ VPValue *StartV = Plan.getOrAddLiveIn(BypassOp->getUnderlyingValue());
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK)) {
// VPReductionPHIRecipes for AnyOf reductions expect a boolean as
// start value; compare the final value from the main vector loop
// to the start value.
- ResumeV = Builder.CreateICmpNE(ResumeV, StartV);
- if (auto *I = dyn_cast<Instruction>(ResumeV))
- InstsToMove.push_back(I);
+ ResumeVPV = PHBuilder.createICmp(CmpInst::ICMP_NE, ResumeVPV, StartV);
} else {
- assert(SentinelVPV && "expected to find icmp using RdxResult");
- if (auto *FreezeI = dyn_cast<FreezeInst>(StartV))
- ToFrozen[FreezeI->getOperand(0)] = StartV;
-
- // Adjust resume: select(icmp eq ResumeV, StartV), Sentinel, ResumeV
- Value *Cmp = Builder.CreateICmpEQ(ResumeV, StartV);
- if (auto *I = dyn_cast<Instruction>(Cmp))
- InstsToMove.push_back(I);
- ResumeV = Builder.CreateSelect(Cmp, SentinelVPV->getLiveInIRValue(),
- ResumeV);
- if (auto *I = dyn_cast<Instruction>(ResumeV))
- InstsToMove.push_back(I);
+ assert(isa<VPIRValue>(SentinelVPV) &&
+ "sentinel must be a live-in to be used in the preheader");
+ VPValue *OrigStart;
+ if (VPlanPatternMatch::match(
+ BypassOp, VPlanPatternMatch::m_Freeze(m_VPValue(OrigStart))))
+ ToFrozen[Plan.getOrAddLiveIn(cast<VPIRValue>(OrigStart))] = StartV;
+
+ // Adjust resume: select(icmp eq ResumeVPV, StartV), Sentinel,
+ // ResumeVPV
+ VPValue *Cmp =
+ PHBuilder.createICmp(CmpInst::ICMP_EQ, ResumeVPV, StartV);
+ ResumeVPV = PHBuilder.createSelect(Cmp, SentinelVPV, ResumeVPV);
}
+ // TODO: materializeBroadcasts does not cover values in the vector
+ // preheader.
+ ReductionPhi->setStartValue(
+ PHBuilder.createNaryOp(VPInstruction::Broadcast, {ResumeVPV}));
----------------
fhahn wrote:
done thanks
https://github.com/llvm/llvm-project/pull/227882
More information about the llvm-commits
mailing list