@@ -7233,28 +7233,29 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
7233
7233
7234
7234
auto *EpiRedHeaderPhi =
7235
7235
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 ();
7245
7243
Value *StartV = EpiRedResult->getOperand (1 )->getLiveInIRValue ();
7246
7244
(void )StartV;
7245
+
7247
7246
auto *Cmp = cast<ICmpInst>(MainResumeValue);
7248
7247
assert (Cmp->getPredicate () == CmpInst::ICMP_NE &&
7249
7248
" AnyOf expected to start with ICMP_NE" );
7250
7249
assert (Cmp->getOperand (1 ) == StartV &&
7251
7250
" AnyOf expected to start by comparing main resume value to original "
7252
7251
" start value" );
7253
7252
MainResumeValue = Cmp->getOperand (0 );
7254
- } else if (RecurrenceDescriptor::isFindLastIVRecurrenceKind (
7255
- RdxDesc.getRecurrenceKind ())) {
7253
+ } else if (RecurrenceDescriptor::isFindLastIVRecurrenceKind (Kind)) {
7256
7254
Value *StartV = getStartValueFromReductionResult (EpiRedResult);
7257
7255
using namespace llvm ::PatternMatch;
7256
+ MainResumeValue = cast<VPInstruction>(EpiRedHeaderPhi->getStartValue ())
7257
+ ->getOperand (0 )
7258
+ ->getUnderlyingValue ();
7258
7259
Value *Cmp, *OrigResumeV, *CmpOp;
7259
7260
bool IsExpectedPattern =
7260
7261
match (MainResumeValue,
@@ -7268,6 +7269,9 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
7268
7269
assert (IsExpectedPattern && " Unexpected reduction resume pattern" );
7269
7270
(void )IsExpectedPattern;
7270
7271
MainResumeValue = OrigResumeV;
7272
+ } else {
7273
+ if (auto *VPI = dyn_cast<VPInstruction>(EpiRedHeaderPhi->getStartValue ()))
7274
+ MainResumeValue = VPI->getOperand (0 )->getUnderlyingValue ();
7271
7275
}
7272
7276
PHINode *MainResumePhi = cast<PHINode>(MainResumeValue);
7273
7277
@@ -9048,8 +9052,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9048
9052
if (!PhiR || !PhiR->isInLoop () || (MinVF.isScalar () && !PhiR->isOrdered ()))
9049
9053
continue ;
9050
9054
9051
- const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
9052
- RecurKind Kind = RdxDesc.getRecurrenceKind ();
9055
+ RecurKind Kind = PhiR->getRecurrenceKind ();
9053
9056
assert (
9054
9057
!RecurrenceDescriptor::isAnyOfRecurrenceKind (Kind) &&
9055
9058
!RecurrenceDescriptor::isFindLastIVRecurrenceKind (Kind) &&
@@ -9155,6 +9158,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9155
9158
if (CM.blockNeedsPredicationForAnyReason (CurrentLinkI->getParent ()))
9156
9159
CondOp = RecipeBuilder.getBlockInMask (CurrentLink->getParent ());
9157
9160
9161
+ const RecurrenceDescriptor &RdxDesc = Legal->getReductionVars ().lookup (
9162
+ cast<PHINode>(PhiR->getUnderlyingInstr ()));
9158
9163
// Non-FP RdxDescs will have all fast math flags set, so clear them.
9159
9164
FastMathFlags FMFs = isa<FPMathOperator>(CurrentLinkI)
9160
9165
? RdxDesc.getFastMathFlags ()
@@ -9185,7 +9190,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9185
9190
if (!PhiR)
9186
9191
continue ;
9187
9192
9188
- const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
9193
+ const RecurrenceDescriptor &RdxDesc = Legal->getReductionVars ().lookup (
9194
+ cast<PHINode>(PhiR->getUnderlyingInstr ()));
9189
9195
Type *PhiTy = PhiR->getUnderlyingValue ()->getType ();
9190
9196
// If tail is folded by masking, introduce selects between the phi
9191
9197
// and the users outside the vector region of each reduction, at the
@@ -9832,14 +9838,9 @@ preparePlanForEpilogueVectorLoop(VPlan &Plan, Loop *L,
9832
9838
}));
9833
9839
ResumeV = cast<PHINode>(ReductionPhi->getUnderlyingInstr ())
9834
9840
->getIncomingValueForBlock (L->getLoopPreheader ());
9835
- const RecurrenceDescriptor &RdxDesc =
9836
- ReductionPhi->getRecurrenceDescriptor ();
9837
- RecurKind RK = RdxDesc.getRecurrenceKind ();
9841
+ RecurKind RK = ReductionPhi->getRecurrenceKind ();
9838
9842
if (RecurrenceDescriptor::isAnyOfRecurrenceKind (RK)) {
9839
9843
Value *StartV = RdxResult->getOperand (1 )->getLiveInIRValue ();
9840
- assert (RdxDesc.getRecurrenceStartValue () == StartV &&
9841
- " start value from ComputeAnyOfResult must match" );
9842
-
9843
9844
// VPReductionPHIRecipes for AnyOf reductions expect a boolean as
9844
9845
// start value; compare the final value from the main vector loop
9845
9846
// to the start value.
@@ -9848,9 +9849,6 @@ preparePlanForEpilogueVectorLoop(VPlan &Plan, Loop *L,
9848
9849
ResumeV = Builder.CreateICmpNE (ResumeV, StartV);
9849
9850
} else if (RecurrenceDescriptor::isFindLastIVRecurrenceKind (RK)) {
9850
9851
Value *StartV = getStartValueFromReductionResult (RdxResult);
9851
- assert (RdxDesc.getRecurrenceStartValue () == StartV &&
9852
- " start value from ComputeFindLastIVResult must match" );
9853
-
9854
9852
ToFrozen[StartV] = cast<PHINode>(ResumeV)->getIncomingValueForBlock (
9855
9853
EPI.MainLoopIterationCountCheck );
9856
9854
0 commit comments