@@ -7266,8 +7266,7 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
72667266
72677267 auto *EpiRedHeaderPhi =
72687268 cast<VPReductionPHIRecipe>(EpiRedResult->getOperand (0 ));
7269- const RecurrenceDescriptor &RdxDesc =
7270- EpiRedHeaderPhi->getRecurrenceDescriptor ();
7269+ RecurKind Kind = EpiRedHeaderPhi->getRecurrenceKind ();
72717270 Value *MainResumeValue;
72727271 if (auto *VPI = dyn_cast<VPInstruction>(EpiRedHeaderPhi->getStartValue ())) {
72737272 assert ((VPI->getOpcode () == VPInstruction::Broadcast ||
@@ -7276,8 +7275,7 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
72767275 MainResumeValue = VPI->getOperand (0 )->getUnderlyingValue ();
72777276 } else
72787277 MainResumeValue = EpiRedHeaderPhi->getStartValue ()->getUnderlyingValue ();
7279- if (RecurrenceDescriptor::isAnyOfRecurrenceKind (
7280- RdxDesc.getRecurrenceKind ())) {
7278+ if (RecurrenceDescriptor::isAnyOfRecurrenceKind (Kind)) {
72817279 [[maybe_unused]] Value *StartV =
72827280 EpiRedResult->getOperand (1 )->getLiveInIRValue ();
72837281 auto *Cmp = cast<ICmpInst>(MainResumeValue);
@@ -7287,8 +7285,7 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
72877285 " AnyOf expected to start by comparing main resume value to original "
72887286 " start value" );
72897287 MainResumeValue = Cmp->getOperand (0 );
7290- } else if (RecurrenceDescriptor::isFindIVRecurrenceKind (
7291- RdxDesc.getRecurrenceKind ())) {
7288+ } else if (RecurrenceDescriptor::isFindIVRecurrenceKind (Kind)) {
72927289 Value *StartV = getStartValueFromReductionResult (EpiRedResult);
72937290 Value *SentinelV = EpiRedResult->getOperand (2 )->getLiveInIRValue ();
72947291 using namespace llvm ::PatternMatch;
@@ -8308,7 +8305,7 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(VPSingleDefRecipe *R,
83088305 unsigned ScaleFactor =
83098306 getScalingForReduction (RdxDesc.getLoopExitInstr ()).value_or (1 );
83108307 PhiRecipe = new VPReductionPHIRecipe (
8311- Phi, RdxDesc, *StartV, CM.isInLoopReduction (Phi),
8308+ Phi, RdxDesc. getRecurrenceKind () , *StartV, CM.isInLoopReduction (Phi),
83128309 CM.useOrderedReductions (RdxDesc), ScaleFactor);
83138310 } else {
83148311 // TODO: Currently fixed-order recurrences are modeled as chains of
@@ -9068,8 +9065,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
90689065 if (!PhiR || !PhiR->isInLoop () || (MinVF.isScalar () && !PhiR->isOrdered ()))
90699066 continue ;
90709067
9071- const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
9072- RecurKind Kind = RdxDesc.getRecurrenceKind ();
9068+ RecurKind Kind = PhiR->getRecurrenceKind ();
90739069 assert (
90749070 !RecurrenceDescriptor::isAnyOfRecurrenceKind (Kind) &&
90759071 !RecurrenceDescriptor::isFindIVRecurrenceKind (Kind) &&
@@ -9175,6 +9171,9 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
91759171 if (CM.blockNeedsPredicationForAnyReason (CurrentLinkI->getParent ()))
91769172 CondOp = RecipeBuilder.getBlockInMask (CurrentLink->getParent ());
91779173
9174+ // TODO: Retrieve FMFs from recipes directly.
9175+ RecurrenceDescriptor RdxDesc = Legal->getRecurrenceDescriptor (
9176+ cast<PHINode>(PhiR->getUnderlyingInstr ()));
91789177 // Non-FP RdxDescs will have all fast math flags set, so clear them.
91799178 FastMathFlags FMFs = isa<FPMathOperator>(CurrentLinkI)
91809179 ? RdxDesc.getFastMathFlags ()
@@ -9205,7 +9204,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
92059204 if (!PhiR)
92069205 continue ;
92079206
9208- const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
9207+ const RecurrenceDescriptor &RdxDesc = Legal->getRecurrenceDescriptor (
9208+ cast<PHINode>(PhiR->getUnderlyingInstr ()));
92099209 Type *PhiTy = PhiR->getUnderlyingValue ()->getType ();
92109210 // If tail is folded by masking, introduce selects between the phi
92119211 // and the users outside the vector region of each reduction, at the
@@ -9253,24 +9253,23 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
92539253 VPInstruction *FinalReductionResult;
92549254 VPBuilder::InsertPointGuard Guard (Builder);
92559255 Builder.setInsertPoint (MiddleVPBB, IP);
9256- if ( RecurrenceDescriptor::isFindIVRecurrenceKind (
9257- RdxDesc. getRecurrenceKind () )) {
9256+ RecurKind RecurrenceKind = PhiR-> getRecurrenceKind ();
9257+ if ( RecurrenceDescriptor::isFindIVRecurrenceKind (RecurrenceKind )) {
92589258 VPValue *Start = PhiR->getStartValue ();
92599259 VPValue *Sentinel = Plan->getOrAddLiveIn (RdxDesc.getSentinelValue ());
92609260 FinalReductionResult =
92619261 Builder.createNaryOp (VPInstruction::ComputeFindIVResult,
92629262 {PhiR, Start, Sentinel, NewExitingVPV}, ExitDL);
9263- } else if (RecurrenceDescriptor::isAnyOfRecurrenceKind (
9264- RdxDesc.getRecurrenceKind ())) {
9263+ } else if (RecurrenceDescriptor::isAnyOfRecurrenceKind (RecurrenceKind)) {
92659264 VPValue *Start = PhiR->getStartValue ();
92669265 FinalReductionResult =
92679266 Builder.createNaryOp (VPInstruction::ComputeAnyOfResult,
92689267 {PhiR, Start, NewExitingVPV}, ExitDL);
92699268 } 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 ();
92749273 FinalReductionResult =
92759274 Builder.createNaryOp (VPInstruction::ComputeReductionResult,
92769275 {PhiR, NewExitingVPV}, Flags, ExitDL);
@@ -9279,11 +9278,9 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
92799278 // then extend the loop exit value to enable InstCombine to evaluate the
92809279 // entire expression in the smaller type.
92819280 if (MinVF.isVector () && PhiTy != RdxDesc.getRecurrenceType () &&
9282- !RecurrenceDescriptor::isAnyOfRecurrenceKind (
9283- RdxDesc.getRecurrenceKind ())) {
9281+ !RecurrenceDescriptor::isAnyOfRecurrenceKind (RecurrenceKind)) {
92849282 assert (!PhiR->isInLoop () && " Unexpected truncated inloop reduction!" );
9285- assert (!RecurrenceDescriptor::isMinMaxRecurrenceKind (
9286- RdxDesc.getRecurrenceKind ()) &&
9283+ assert (!RecurrenceDescriptor::isMinMaxRecurrenceKind (RecurrenceKind) &&
92879284 " Unexpected truncated min-max recurrence!" );
92889285 Type *RdxTy = RdxDesc.getRecurrenceType ();
92899286 auto *Trunc =
@@ -9319,8 +9316,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
93199316 // with a boolean reduction phi node to check if the condition is true in
93209317 // any iteration. The final value is selected by the final
93219318 // ComputeReductionResult.
9322- if (RecurrenceDescriptor::isAnyOfRecurrenceKind (
9323- RdxDesc.getRecurrenceKind ())) {
9319+ if (RecurrenceDescriptor::isAnyOfRecurrenceKind (RecurrenceKind)) {
93249320 auto *Select = cast<VPRecipeBase>(*find_if (PhiR->users (), [](VPUser *U) {
93259321 return isa<VPWidenSelectRecipe>(U) ||
93269322 (isa<VPReplicateRecipe>(U) &&
@@ -9851,14 +9847,9 @@ preparePlanForEpilogueVectorLoop(VPlan &Plan, Loop *L,
98519847 }));
98529848 ResumeV = cast<PHINode>(ReductionPhi->getUnderlyingInstr ())
98539849 ->getIncomingValueForBlock (L->getLoopPreheader ());
9854- const RecurrenceDescriptor &RdxDesc =
9855- ReductionPhi->getRecurrenceDescriptor ();
9856- RecurKind RK = RdxDesc.getRecurrenceKind ();
9850+ RecurKind RK = ReductionPhi->getRecurrenceKind ();
98579851 if (RecurrenceDescriptor::isAnyOfRecurrenceKind (RK)) {
98589852 Value *StartV = RdxResult->getOperand (1 )->getLiveInIRValue ();
9859- assert (RdxDesc.getRecurrenceStartValue () == StartV &&
9860- " start value from ComputeAnyOfResult must match" );
9861-
98629853 // VPReductionPHIRecipes for AnyOf reductions expect a boolean as
98639854 // start value; compare the final value from the main vector loop
98649855 // to the start value.
@@ -9867,9 +9858,6 @@ preparePlanForEpilogueVectorLoop(VPlan &Plan, Loop *L,
98679858 ResumeV = Builder.CreateICmpNE (ResumeV, StartV);
98689859 } else if (RecurrenceDescriptor::isFindIVRecurrenceKind (RK)) {
98699860 Value *StartV = getStartValueFromReductionResult (RdxResult);
9870- assert (RdxDesc.getRecurrenceStartValue () == StartV &&
9871- " start value from ComputeFinIVResult must match" );
9872-
98739861 ToFrozen[StartV] = cast<PHINode>(ResumeV)->getIncomingValueForBlock (
98749862 EPI.MainLoopIterationCountCheck );
98759863
0 commit comments