@@ -4047,6 +4047,7 @@ static bool willGenerateVectors(VPlan &Plan, ElementCount VF,
40474047 case VPDef::VPWidenIntrinsicSC:
40484048 case VPDef::VPWidenSC:
40494049 case VPDef::VPWidenSelectSC:
4050+ case VPDef::VPWidenSelectVectorSC:
40504051 case VPDef::VPBlendSC:
40514052 case VPDef::VPFirstOrderRecurrencePHISC:
40524053 case VPDef::VPHistogramSC:
@@ -4546,6 +4547,11 @@ LoopVectorizationPlanner::selectInterleaveCount(VPlan &Plan, ElementCount VF,
45464547 any_of (Plan.getVectorLoopRegion ()->getEntryBasicBlock ()->phis (),
45474548 IsaPred<VPReductionPHIRecipe>);
45484549
4550+ // FIXME: implement interleaving for FindLast transform correctly.
4551+ for (auto &[_, RdxDesc] : Legal->getReductionVars ())
4552+ if (RecurrenceDescriptor::isFindLastRecurrenceKind (RdxDesc.getRecurrenceKind ()))
4553+ return 1 ;
4554+
45494555 // If we did not calculate the cost for VF (because the user selected the VF)
45504556 // then we calculate the cost of VF here.
45514557 if (LoopCost == 0 ) {
@@ -8687,6 +8693,10 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
86878693 *Plan, Builder))
86888694 return nullptr ;
86898695
8696+ // Create whole-vector selects for find-last recurrences.
8697+ VPlanTransforms::runPass (VPlanTransforms::convertFindLastRecurrences,
8698+ *Plan, RecipeBuilder, Legal);
8699+
86908700 if (useActiveLaneMask (Style)) {
86918701 // TODO: Move checks to VPlanTransforms::addActiveLaneMask once
86928702 // TailFoldingStyle is visible there.
@@ -8779,6 +8789,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
87798789
87808790 RecurKind Kind = PhiR->getRecurrenceKind ();
87818791 assert (
8792+ !RecurrenceDescriptor::isFindLastRecurrenceKind (Kind) &&
87828793 !RecurrenceDescriptor::isAnyOfRecurrenceKind (Kind) &&
87838794 !RecurrenceDescriptor::isFindIVRecurrenceKind (Kind) &&
87848795 " AnyOf and FindIV reductions are not allowed for in-loop reductions" );
@@ -8987,6 +8998,10 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
89878998 FinalReductionResult =
89888999 Builder.createNaryOp (VPInstruction::ComputeAnyOfResult,
89899000 {PhiR, Start, NewExitingVPV}, ExitDL);
9001+ } else if (RecurrenceDescriptor::isFindLastRecurrenceKind (
9002+ RdxDesc.getRecurrenceKind ())) {
9003+ FinalReductionResult = Builder.createNaryOp (
9004+ VPInstruction::ExtractLastActive, {NewExitingVPV}, ExitDL);
89909005 } else {
89919006 VPIRFlags Flags =
89929007 RecurrenceDescriptor::isFloatingPointRecurrenceKind (RecurrenceKind)
@@ -9076,7 +9091,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
90769091 RecurKind RK = RdxDesc.getRecurrenceKind ();
90779092 if ((!RecurrenceDescriptor::isAnyOfRecurrenceKind (RK) &&
90789093 !RecurrenceDescriptor::isFindIVRecurrenceKind (RK) &&
9079- !RecurrenceDescriptor::isMinMaxRecurrenceKind (RK))) {
9094+ !RecurrenceDescriptor::isMinMaxRecurrenceKind (RK) &&
9095+ !RecurrenceDescriptor::isFindLastRecurrenceKind (RK))) {
90809096 VPBuilder PHBuilder (Plan->getVectorPreheader ());
90819097 VPValue *Iden = Plan->getOrAddLiveIn (
90829098 getRecurrenceIdentity (RK, PhiTy, RdxDesc.getFastMathFlags ()));
@@ -10069,6 +10085,21 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1006910085 // Override IC if user provided an interleave count.
1007010086 IC = UserIC > 0 ? UserIC : IC;
1007110087
10088+ // FIXME: Enable interleaving for last_active reductions.
10089+ if (any_of (LVL.getReductionVars (), [&](auto &Reduction) -> bool {
10090+ const RecurrenceDescriptor &RdxDesc = Reduction.second ;
10091+ return RecurrenceDescriptor::isFindLastRecurrenceKind (RdxDesc.getRecurrenceKind ());
10092+ })) {
10093+ LLVM_DEBUG (dbgs () << " LV: Not interleaving without vectorization due "
10094+ << " to conditional scalar assignments.\n " );
10095+ IntDiagMsg = {
10096+ " ConditionalAssignmentPreventsScalarInterleaving" ,
10097+ " Unable to interleave without vectorization due to conditional "
10098+ " assignments" };
10099+ InterleaveLoop = false ;
10100+ IC = 1 ;
10101+ }
10102+
1007210103 // Emit diagnostic messages, if any.
1007310104 const char *VAPassName = Hints.vectorizeAnalysisPassName ();
1007410105 if (!VectorizeLoop && !InterleaveLoop) {
0 commit comments