@@ -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);
0 commit comments