@@ -7266,8 +7266,7 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
7266
7266
7267
7267
auto *EpiRedHeaderPhi =
7268
7268
cast<VPReductionPHIRecipe>(EpiRedResult->getOperand (0 ));
7269
- const RecurrenceDescriptor &RdxDesc =
7270
- EpiRedHeaderPhi->getRecurrenceDescriptor ();
7269
+ RecurKind Kind = EpiRedHeaderPhi->getRecurrenceKind ();
7271
7270
Value *MainResumeValue;
7272
7271
if (auto *VPI = dyn_cast<VPInstruction>(EpiRedHeaderPhi->getStartValue ())) {
7273
7272
assert ((VPI->getOpcode () == VPInstruction::Broadcast ||
@@ -7276,8 +7275,7 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
7276
7275
MainResumeValue = VPI->getOperand (0 )->getUnderlyingValue ();
7277
7276
} else
7278
7277
MainResumeValue = EpiRedHeaderPhi->getStartValue ()->getUnderlyingValue ();
7279
- if (RecurrenceDescriptor::isAnyOfRecurrenceKind (
7280
- RdxDesc.getRecurrenceKind ())) {
7278
+ if (RecurrenceDescriptor::isAnyOfRecurrenceKind (Kind)) {
7281
7279
[[maybe_unused]] Value *StartV =
7282
7280
EpiRedResult->getOperand (1 )->getLiveInIRValue ();
7283
7281
auto *Cmp = cast<ICmpInst>(MainResumeValue);
@@ -7287,8 +7285,7 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
7287
7285
" AnyOf expected to start by comparing main resume value to original "
7288
7286
" start value" );
7289
7287
MainResumeValue = Cmp->getOperand (0 );
7290
- } else if (RecurrenceDescriptor::isFindIVRecurrenceKind (
7291
- RdxDesc.getRecurrenceKind ())) {
7288
+ } else if (RecurrenceDescriptor::isFindIVRecurrenceKind (Kind)) {
7292
7289
Value *StartV = getStartValueFromReductionResult (EpiRedResult);
7293
7290
Value *SentinelV = EpiRedResult->getOperand (2 )->getLiveInIRValue ();
7294
7291
using namespace llvm ::PatternMatch;
@@ -8308,7 +8305,7 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(VPSingleDefRecipe *R,
8308
8305
unsigned ScaleFactor =
8309
8306
getScalingForReduction (RdxDesc.getLoopExitInstr ()).value_or (1 );
8310
8307
PhiRecipe = new VPReductionPHIRecipe (
8311
- Phi, RdxDesc, *StartV, CM.isInLoopReduction (Phi),
8308
+ Phi, RdxDesc. getRecurrenceKind () , *StartV, CM.isInLoopReduction (Phi),
8312
8309
CM.useOrderedReductions (RdxDesc), ScaleFactor);
8313
8310
} else {
8314
8311
// TODO: Currently fixed-order recurrences are modeled as chains of
@@ -9068,8 +9065,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9068
9065
if (!PhiR || !PhiR->isInLoop () || (MinVF.isScalar () && !PhiR->isOrdered ()))
9069
9066
continue ;
9070
9067
9071
- const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
9072
- RecurKind Kind = RdxDesc.getRecurrenceKind ();
9068
+ RecurKind Kind = PhiR->getRecurrenceKind ();
9073
9069
assert (
9074
9070
!RecurrenceDescriptor::isAnyOfRecurrenceKind (Kind) &&
9075
9071
!RecurrenceDescriptor::isFindIVRecurrenceKind (Kind) &&
@@ -9175,6 +9171,9 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9175
9171
if (CM.blockNeedsPredicationForAnyReason (CurrentLinkI->getParent ()))
9176
9172
CondOp = RecipeBuilder.getBlockInMask (CurrentLink->getParent ());
9177
9173
9174
+ // TODO: Retrieve FMFs from recipes directly.
9175
+ RecurrenceDescriptor RdxDesc = Legal->getRecurrenceDescriptor (
9176
+ cast<PHINode>(PhiR->getUnderlyingInstr ()));
9178
9177
// Non-FP RdxDescs will have all fast math flags set, so clear them.
9179
9178
FastMathFlags FMFs = isa<FPMathOperator>(CurrentLinkI)
9180
9179
? RdxDesc.getFastMathFlags ()
@@ -9205,7 +9204,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9205
9204
if (!PhiR)
9206
9205
continue ;
9207
9206
9208
- const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
9207
+ const RecurrenceDescriptor &RdxDesc = Legal->getRecurrenceDescriptor (
9208
+ cast<PHINode>(PhiR->getUnderlyingInstr ()));
9209
9209
Type *PhiTy = PhiR->getUnderlyingValue ()->getType ();
9210
9210
// If tail is folded by masking, introduce selects between the phi
9211
9211
// and the users outside the vector region of each reduction, at the
@@ -9253,24 +9253,23 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9253
9253
VPInstruction *FinalReductionResult;
9254
9254
VPBuilder::InsertPointGuard Guard (Builder);
9255
9255
Builder.setInsertPoint (MiddleVPBB, IP);
9256
- if ( RecurrenceDescriptor::isFindIVRecurrenceKind (
9257
- RdxDesc. getRecurrenceKind () )) {
9256
+ RecurKind RecurrenceKind = PhiR-> getRecurrenceKind ();
9257
+ if ( RecurrenceDescriptor::isFindIVRecurrenceKind (RecurrenceKind )) {
9258
9258
VPValue *Start = PhiR->getStartValue ();
9259
9259
VPValue *Sentinel = Plan->getOrAddLiveIn (RdxDesc.getSentinelValue ());
9260
9260
FinalReductionResult =
9261
9261
Builder.createNaryOp (VPInstruction::ComputeFindIVResult,
9262
9262
{PhiR, Start, Sentinel, NewExitingVPV}, ExitDL);
9263
- } else if (RecurrenceDescriptor::isAnyOfRecurrenceKind (
9264
- RdxDesc.getRecurrenceKind ())) {
9263
+ } else if (RecurrenceDescriptor::isAnyOfRecurrenceKind (RecurrenceKind)) {
9265
9264
VPValue *Start = PhiR->getStartValue ();
9266
9265
FinalReductionResult =
9267
9266
Builder.createNaryOp (VPInstruction::ComputeAnyOfResult,
9268
9267
{PhiR, Start, NewExitingVPV}, ExitDL);
9269
9268
} else {
9270
- VPIRFlags Flags = RecurrenceDescriptor::isFloatingPointRecurrenceKind (
9271
- RdxDesc. getRecurrenceKind () )
9272
- ? VPIRFlags (RdxDesc.getFastMathFlags ())
9273
- : VPIRFlags ();
9269
+ VPIRFlags Flags =
9270
+ RecurrenceDescriptor::isFloatingPointRecurrenceKind (RecurrenceKind )
9271
+ ? VPIRFlags (RdxDesc.getFastMathFlags ())
9272
+ : VPIRFlags ();
9274
9273
FinalReductionResult =
9275
9274
Builder.createNaryOp (VPInstruction::ComputeReductionResult,
9276
9275
{PhiR, NewExitingVPV}, Flags, ExitDL);
@@ -9279,11 +9278,9 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9279
9278
// then extend the loop exit value to enable InstCombine to evaluate the
9280
9279
// entire expression in the smaller type.
9281
9280
if (MinVF.isVector () && PhiTy != RdxDesc.getRecurrenceType () &&
9282
- !RecurrenceDescriptor::isAnyOfRecurrenceKind (
9283
- RdxDesc.getRecurrenceKind ())) {
9281
+ !RecurrenceDescriptor::isAnyOfRecurrenceKind (RecurrenceKind)) {
9284
9282
assert (!PhiR->isInLoop () && " Unexpected truncated inloop reduction!" );
9285
- assert (!RecurrenceDescriptor::isMinMaxRecurrenceKind (
9286
- RdxDesc.getRecurrenceKind ()) &&
9283
+ assert (!RecurrenceDescriptor::isMinMaxRecurrenceKind (RecurrenceKind) &&
9287
9284
" Unexpected truncated min-max recurrence!" );
9288
9285
Type *RdxTy = RdxDesc.getRecurrenceType ();
9289
9286
auto *Trunc =
@@ -9319,8 +9316,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
9319
9316
// with a boolean reduction phi node to check if the condition is true in
9320
9317
// any iteration. The final value is selected by the final
9321
9318
// ComputeReductionResult.
9322
- if (RecurrenceDescriptor::isAnyOfRecurrenceKind (
9323
- RdxDesc.getRecurrenceKind ())) {
9319
+ if (RecurrenceDescriptor::isAnyOfRecurrenceKind (RecurrenceKind)) {
9324
9320
auto *Select = cast<VPRecipeBase>(*find_if (PhiR->users (), [](VPUser *U) {
9325
9321
return isa<VPWidenSelectRecipe>(U) ||
9326
9322
(isa<VPReplicateRecipe>(U) &&
@@ -9851,14 +9847,9 @@ preparePlanForEpilogueVectorLoop(VPlan &Plan, Loop *L,
9851
9847
}));
9852
9848
ResumeV = cast<PHINode>(ReductionPhi->getUnderlyingInstr ())
9853
9849
->getIncomingValueForBlock (L->getLoopPreheader ());
9854
- const RecurrenceDescriptor &RdxDesc =
9855
- ReductionPhi->getRecurrenceDescriptor ();
9856
- RecurKind RK = RdxDesc.getRecurrenceKind ();
9850
+ RecurKind RK = ReductionPhi->getRecurrenceKind ();
9857
9851
if (RecurrenceDescriptor::isAnyOfRecurrenceKind (RK)) {
9858
9852
Value *StartV = RdxResult->getOperand (1 )->getLiveInIRValue ();
9859
- assert (RdxDesc.getRecurrenceStartValue () == StartV &&
9860
- " start value from ComputeAnyOfResult must match" );
9861
-
9862
9853
// VPReductionPHIRecipes for AnyOf reductions expect a boolean as
9863
9854
// start value; compare the final value from the main vector loop
9864
9855
// to the start value.
@@ -9867,9 +9858,6 @@ preparePlanForEpilogueVectorLoop(VPlan &Plan, Loop *L,
9867
9858
ResumeV = Builder.CreateICmpNE (ResumeV, StartV);
9868
9859
} else if (RecurrenceDescriptor::isFindIVRecurrenceKind (RK)) {
9869
9860
Value *StartV = getStartValueFromReductionResult (RdxResult);
9870
- assert (RdxDesc.getRecurrenceStartValue () == StartV &&
9871
- " start value from ComputeFinIVResult must match" );
9872
-
9873
9861
ToFrozen[StartV] = cast<PHINode>(ResumeV)->getIncomingValueForBlock (
9874
9862
EPI.MainLoopIterationCountCheck );
9875
9863
0 commit comments