Skip to content

Commit 732ebf8

Browse files
committed
[VPlan] Address post-commit comments for f688480.
Assign sentinel value to named variable to clarify naming and update comments. Addresses post-commit comments from #142291.
1 parent 892513e commit 732ebf8

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7263,14 +7263,13 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
72637263
} else if (RecurrenceDescriptor::isFindLastIVRecurrenceKind(
72647264
RdxDesc.getRecurrenceKind())) {
72657265
Value *StartV = getStartValueFromReductionResult(EpiRedResult);
7266+
Value *SentinelV = EpiRedResult->getOperand(2)->getLiveInIRValue();
72667267
using namespace llvm::PatternMatch;
72677268
Value *Cmp, *OrigResumeV, *CmpOp;
72687269
bool IsExpectedPattern =
72697270
match(MainResumeValue,
7270-
m_Select(
7271-
m_OneUse(m_Value(Cmp)),
7272-
m_Specific(EpiRedResult->getOperand(2)->getLiveInIRValue()),
7273-
m_Value(OrigResumeV))) &&
7271+
m_Select(m_OneUse(m_Value(Cmp)), m_Specific(SentinelV),
7272+
m_Value(OrigResumeV))) &&
72747273
(match(Cmp, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Specific(OrigResumeV),
72757274
m_Value(CmpOp))) &&
72767275
((CmpOp == StartV && isGuaranteedNotToBeUndefOrPoison(CmpOp))));
@@ -9224,11 +9223,10 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
92249223
if (RecurrenceDescriptor::isFindLastIVRecurrenceKind(
92259224
RdxDesc.getRecurrenceKind())) {
92269225
VPValue *Start = PhiR->getStartValue();
9227-
FinalReductionResult = Builder.createNaryOp(
9228-
VPInstruction::ComputeFindLastIVResult,
9229-
{PhiR, Start, Plan->getOrAddLiveIn(RdxDesc.getSentinelValue()),
9230-
NewExitingVPV},
9231-
ExitDL);
9226+
VPValue *Sentinel = Plan->getOrAddLiveIn(RdxDesc.getSentinelValue());
9227+
FinalReductionResult =
9228+
Builder.createNaryOp(VPInstruction::ComputeFindLastIVResult,
9229+
{PhiR, Start, Sentinel, NewExitingVPV}, ExitDL);
92329230
} else if (RecurrenceDescriptor::isAnyOfRecurrenceKind(
92339231
RdxDesc.getRecurrenceKind())) {
92349232
VPValue *Start = PhiR->getStartValue();
@@ -9816,8 +9814,8 @@ preparePlanForEpilogueVectorLoop(VPlan &Plan, Loop *L,
98169814
BasicBlock *ResumeBB = cast<Instruction>(ResumeV)->getParent();
98179815
IRBuilder<> Builder(ResumeBB, ResumeBB->getFirstNonPHIIt());
98189816
Value *Cmp = Builder.CreateICmpEQ(ResumeV, ToFrozen[StartV]);
9819-
ResumeV = Builder.CreateSelect(
9820-
Cmp, RdxResult->getOperand(2)->getLiveInIRValue(), ResumeV);
9817+
Value *Sentinel = RdxResult->getOperand(2)->getLiveInIRValue();
9818+
ResumeV = Builder.CreateSelect(Cmp, Sentinel, ResumeV);
98219819
} else {
98229820
VPValue *StartVal = Plan.getOrAddLiveIn(ResumeV);
98239821
auto *PhiR = dyn_cast<VPReductionPHIRecipe>(&R);

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,18 +643,18 @@ Value *VPInstruction::generate(VPTransformState &State) {
643643
assert(!PhiR->isInLoop() &&
644644
"In-loop FindLastIV reduction is not supported yet");
645645

646-
// The recipe's operands are the reduction phi, followed by one operand for
647-
// each part of the reduction.
646+
// The recipe's operands are the reduction phi, the start value, the
647+
// sentinel value, followed by one operand for each part of the reduction.
648648
unsigned UF = getNumOperands() - 3;
649649
Value *ReducedPartRdx = State.get(getOperand(3));
650650
for (unsigned Part = 1; Part < UF; ++Part) {
651651
ReducedPartRdx = createMinMaxOp(Builder, RecurKind::SMax, ReducedPartRdx,
652652
State.get(getOperand(3 + Part)));
653653
}
654654

655-
return createFindLastIVReduction(Builder, ReducedPartRdx,
656-
State.get(getOperand(1), true),
657-
getOperand(2)->getLiveInIRValue());
655+
Value *Start = State.get(getOperand(1), true);
656+
Value *Sentinel = getOperand(2)->getLiveInIRValue();
657+
return createFindLastIVReduction(Builder, ReducedPartRdx, Start, Sentinel);
658658
}
659659
case VPInstruction::ComputeReductionResult: {
660660
// FIXME: The cross-recipe dependency on VPReductionPHIRecipe is temporary

0 commit comments

Comments
 (0)