@@ -4052,6 +4052,7 @@ static bool willGenerateVectors(VPlan &Plan, ElementCount VF,
40524052 case VPDef::VPWidenIntrinsicSC:
40534053 case VPDef::VPWidenSC:
40544054 case VPDef::VPWidenSelectSC:
4055+ case VPDef::VPWidenSelectVectorSC:
40554056 case VPDef::VPBlendSC:
40564057 case VPDef::VPFirstOrderRecurrencePHISC:
40574058 case VPDef::VPHistogramSC:
@@ -4559,6 +4560,12 @@ LoopVectorizationPlanner::selectInterleaveCount(VPlan &Plan, ElementCount VF,
45594560 any_of (Plan.getVectorLoopRegion ()->getEntryBasicBlock ()->phis (),
45604561 IsaPred<VPReductionPHIRecipe>);
45614562
4563+ // FIXME: implement interleaving for FindLast transform correctly.
4564+ for (auto &[_, RdxDesc] : Legal->getReductionVars ())
4565+ if (RecurrenceDescriptor::isFindLastRecurrenceKind (
4566+ RdxDesc.getRecurrenceKind ()))
4567+ return 1 ;
4568+
45624569 // If we did not calculate the cost for VF (because the user selected the VF)
45634570 // then we calculate the cost of VF here.
45644571 if (LoopCost == 0 ) {
@@ -8472,6 +8479,10 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
84728479 *Plan, Builder))
84738480 return nullptr ;
84748481
8482+ // Create whole-vector selects for find-last recurrences.
8483+ VPlanTransforms::runPass (VPlanTransforms::convertFindLastRecurrences, *Plan,
8484+ RecipeBuilder, Legal);
8485+
84758486 if (useActiveLaneMask (Style)) {
84768487 // TODO: Move checks to VPlanTransforms::addActiveLaneMask once
84778488 // TailFoldingStyle is visible there.
@@ -8566,6 +8577,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
85668577
85678578 RecurKind Kind = PhiR->getRecurrenceKind ();
85688579 assert (
8580+ !RecurrenceDescriptor::isFindLastRecurrenceKind (Kind) &&
85698581 !RecurrenceDescriptor::isAnyOfRecurrenceKind (Kind) &&
85708582 !RecurrenceDescriptor::isFindIVRecurrenceKind (Kind) &&
85718583 " AnyOf and FindIV reductions are not allowed for in-loop reductions" );
@@ -8774,6 +8786,10 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
87748786 FinalReductionResult =
87758787 Builder.createNaryOp (VPInstruction::ComputeAnyOfResult,
87768788 {PhiR, Start, NewExitingVPV}, ExitDL);
8789+ } else if (RecurrenceDescriptor::isFindLastRecurrenceKind (
8790+ RdxDesc.getRecurrenceKind ())) {
8791+ FinalReductionResult = Builder.createNaryOp (
8792+ VPInstruction::ExtractLastActive, {NewExitingVPV}, ExitDL);
87778793 } else {
87788794 VPIRFlags Flags =
87798795 RecurrenceDescriptor::isFloatingPointRecurrenceKind (RecurrenceKind)
@@ -8869,7 +8885,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
88698885 RecurKind RK = RdxDesc.getRecurrenceKind ();
88708886 if ((!RecurrenceDescriptor::isAnyOfRecurrenceKind (RK) &&
88718887 !RecurrenceDescriptor::isFindIVRecurrenceKind (RK) &&
8872- !RecurrenceDescriptor::isMinMaxRecurrenceKind (RK))) {
8888+ !RecurrenceDescriptor::isMinMaxRecurrenceKind (RK) &&
8889+ !RecurrenceDescriptor::isFindLastRecurrenceKind (RK))) {
88738890 VPBuilder PHBuilder (Plan->getVectorPreheader ());
88748891 VPValue *Iden = Plan->getOrAddLiveIn (
88758892 getRecurrenceIdentity (RK, PhiTy, RdxDesc.getFastMathFlags ()));
@@ -9993,6 +10010,22 @@ bool LoopVectorizePass::processLoop(Loop *L) {
999310010 // Override IC if user provided an interleave count.
999410011 IC = UserIC > 0 ? UserIC : IC;
999510012
10013+ // FIXME: Enable interleaving for last_active reductions.
10014+ if (any_of (LVL.getReductionVars (), [&](auto &Reduction) -> bool {
10015+ const RecurrenceDescriptor &RdxDesc = Reduction.second ;
10016+ return RecurrenceDescriptor::isFindLastRecurrenceKind (
10017+ RdxDesc.getRecurrenceKind ());
10018+ })) {
10019+ LLVM_DEBUG (dbgs () << " LV: Not interleaving without vectorization due "
10020+ << " to conditional scalar assignments.\n " );
10021+ IntDiagMsg = {
10022+ " ConditionalAssignmentPreventsScalarInterleaving" ,
10023+ " Unable to interleave without vectorization due to conditional "
10024+ " assignments" };
10025+ InterleaveLoop = false ;
10026+ IC = 1 ;
10027+ }
10028+
999610029 // Emit diagnostic messages, if any.
999710030 const char *VAPassName = Hints.vectorizeAnalysisPassName ();
999810031 if (!VectorizeLoop && !InterleaveLoop) {
0 commit comments