@@ -7233,28 +7233,29 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
72337233
72347234  auto  *EpiRedHeaderPhi =
72357235      cast<VPReductionPHIRecipe>(EpiRedResult->getOperand (0 ));
7236-   const  RecurrenceDescriptor &RdxDesc =
7237-       EpiRedHeaderPhi->getRecurrenceDescriptor ();
7238-   Value *MainResumeValue;
7239-   if  (auto  *VPI = dyn_cast<VPInstruction>(EpiRedHeaderPhi->getStartValue ()))
7240-     MainResumeValue = VPI->getOperand (0 )->getUnderlyingValue ();
7241-   else 
7242-     MainResumeValue = EpiRedHeaderPhi->getStartValue ()->getUnderlyingValue ();
7243-   if  (RecurrenceDescriptor::isAnyOfRecurrenceKind (
7244-           RdxDesc.getRecurrenceKind ())) {
7236+   RecurKind Kind = EpiRedHeaderPhi->getRecurrenceKind ();
7237+   Value *MainResumeValue =
7238+       EpiRedHeaderPhi->getStartValue ()->getUnderlyingValue ();
7239+   if  (RecurrenceDescriptor::isAnyOfRecurrenceKind (Kind)) {
7240+     MainResumeValue = cast<VPInstruction>(EpiRedHeaderPhi->getStartValue ())
7241+                           ->getOperand (0 )
7242+                           ->getUnderlyingValue ();
72457243    Value *StartV = EpiRedResult->getOperand (1 )->getLiveInIRValue ();
72467244    (void )StartV;
7245+ 
72477246    auto  *Cmp = cast<ICmpInst>(MainResumeValue);
72487247    assert (Cmp->getPredicate () == CmpInst::ICMP_NE &&
72497248           " AnyOf expected to start with ICMP_NE"  );
72507249    assert (Cmp->getOperand (1 ) == StartV &&
72517250           " AnyOf expected to start by comparing main resume value to original " 
72527251           " start value"  );
72537252    MainResumeValue = Cmp->getOperand (0 );
7254-   } else  if  (RecurrenceDescriptor::isFindLastIVRecurrenceKind (
7255-                  RdxDesc.getRecurrenceKind ())) {
7253+   } else  if  (RecurrenceDescriptor::isFindLastIVRecurrenceKind (Kind)) {
72567254    Value *StartV = getStartValueFromReductionResult (EpiRedResult);
72577255    using  namespace  llvm ::PatternMatch; 
7256+     MainResumeValue = cast<VPInstruction>(EpiRedHeaderPhi->getStartValue ())
7257+                           ->getOperand (0 )
7258+                           ->getUnderlyingValue ();
72587259    Value *Cmp, *OrigResumeV, *CmpOp;
72597260    bool  IsExpectedPattern =
72607261        match (MainResumeValue,
@@ -7268,6 +7269,9 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
72687269    assert (IsExpectedPattern && " Unexpected reduction resume pattern"  );
72697270    (void )IsExpectedPattern;
72707271    MainResumeValue = OrigResumeV;
7272+   } else  {
7273+     if  (auto  *VPI = dyn_cast<VPInstruction>(EpiRedHeaderPhi->getStartValue ()))
7274+       MainResumeValue = VPI->getOperand (0 )->getUnderlyingValue ();
72717275  }
72727276  PHINode *MainResumePhi = cast<PHINode>(MainResumeValue);
72737277
@@ -9048,8 +9052,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
90489052    if  (!PhiR || !PhiR->isInLoop () || (MinVF.isScalar () && !PhiR->isOrdered ()))
90499053      continue ;
90509054
9051-     const  RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
9052-     RecurKind Kind = RdxDesc.getRecurrenceKind ();
9055+     RecurKind Kind = PhiR->getRecurrenceKind ();
90539056    assert (
90549057        !RecurrenceDescriptor::isAnyOfRecurrenceKind (Kind) &&
90559058        !RecurrenceDescriptor::isFindLastIVRecurrenceKind (Kind) &&
@@ -9155,6 +9158,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
91559158      if  (CM.blockNeedsPredicationForAnyReason (CurrentLinkI->getParent ()))
91569159        CondOp = RecipeBuilder.getBlockInMask (CurrentLink->getParent ());
91579160
9161+       const  RecurrenceDescriptor &RdxDesc = Legal->getReductionVars ().lookup (
9162+           cast<PHINode>(PhiR->getUnderlyingInstr ()));
91589163      //  Non-FP RdxDescs will have all fast math flags set, so clear them.
91599164      FastMathFlags FMFs = isa<FPMathOperator>(CurrentLinkI)
91609165                               ? RdxDesc.getFastMathFlags ()
@@ -9185,7 +9190,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
91859190    if  (!PhiR)
91869191      continue ;
91879192
9188-     const  RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
9193+     const  RecurrenceDescriptor &RdxDesc = Legal->getReductionVars ().lookup (
9194+         cast<PHINode>(PhiR->getUnderlyingInstr ()));
91899195    Type *PhiTy = PhiR->getUnderlyingValue ()->getType ();
91909196    //  If tail is folded by masking, introduce selects between the phi
91919197    //  and the users outside the vector region of each reduction, at the
@@ -9832,14 +9838,9 @@ preparePlanForEpilogueVectorLoop(VPlan &Plan, Loop *L,
98329838          }));
98339839      ResumeV = cast<PHINode>(ReductionPhi->getUnderlyingInstr ())
98349840                    ->getIncomingValueForBlock (L->getLoopPreheader ());
9835-       const  RecurrenceDescriptor &RdxDesc =
9836-           ReductionPhi->getRecurrenceDescriptor ();
9837-       RecurKind RK = RdxDesc.getRecurrenceKind ();
9841+       RecurKind RK = ReductionPhi->getRecurrenceKind ();
98389842      if  (RecurrenceDescriptor::isAnyOfRecurrenceKind (RK)) {
98399843        Value *StartV = RdxResult->getOperand (1 )->getLiveInIRValue ();
9840-         assert (RdxDesc.getRecurrenceStartValue () == StartV &&
9841-                " start value from ComputeAnyOfResult must match"  );
9842- 
98439844        //  VPReductionPHIRecipes for AnyOf reductions expect a boolean as
98449845        //  start value; compare the final value from the main vector loop
98459846        //  to the start value.
@@ -9848,9 +9849,6 @@ preparePlanForEpilogueVectorLoop(VPlan &Plan, Loop *L,
98489849        ResumeV = Builder.CreateICmpNE (ResumeV, StartV);
98499850      } else  if  (RecurrenceDescriptor::isFindLastIVRecurrenceKind (RK)) {
98509851        Value *StartV = getStartValueFromReductionResult (RdxResult);
9851-         assert (RdxDesc.getRecurrenceStartValue () == StartV &&
9852-                " start value from ComputeFindLastIVResult must match"  );
9853- 
98549852        ToFrozen[StartV] = cast<PHINode>(ResumeV)->getIncomingValueForBlock (
98559853            EPI.MainLoopIterationCountCheck );
98569854
0 commit comments