@@ -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:
@@ -4546,6 +4547,12 @@ 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 (
4553+ RdxDesc.getRecurrenceKind ()))
4554+ return 1 ;
4555+
45494556 // If we did not calculate the cost for VF (because the user selected the VF)
45504557 // then we calculate the cost of VF here.
45514558 if (LoopCost == 0 ) {
@@ -8459,6 +8466,10 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
84598466 *Plan, Builder))
84608467 return nullptr ;
84618468
8469+ // Create whole-vector selects for find-last recurrences.
8470+ VPlanTransforms::runPass (VPlanTransforms::convertFindLastRecurrences, *Plan,
8471+ RecipeBuilder, Legal);
8472+
84628473 if (useActiveLaneMask (Style)) {
84638474 // TODO: Move checks to VPlanTransforms::addActiveLaneMask once
84648475 // TailFoldingStyle is visible there.
@@ -8553,6 +8564,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
85538564
85548565 RecurKind Kind = PhiR->getRecurrenceKind ();
85558566 assert (
8567+ !RecurrenceDescriptor::isFindLastRecurrenceKind (Kind) &&
85568568 !RecurrenceDescriptor::isAnyOfRecurrenceKind (Kind) &&
85578569 !RecurrenceDescriptor::isFindIVRecurrenceKind (Kind) &&
85588570 " AnyOf and FindIV reductions are not allowed for in-loop reductions" );
@@ -8761,6 +8773,10 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
87618773 FinalReductionResult =
87628774 Builder.createNaryOp (VPInstruction::ComputeAnyOfResult,
87638775 {PhiR, Start, NewExitingVPV}, ExitDL);
8776+ } else if (RecurrenceDescriptor::isFindLastRecurrenceKind (
8777+ RdxDesc.getRecurrenceKind ())) {
8778+ FinalReductionResult = Builder.createNaryOp (
8779+ VPInstruction::ExtractLastActive, {NewExitingVPV}, ExitDL);
87648780 } else {
87658781 VPIRFlags Flags =
87668782 RecurrenceDescriptor::isFloatingPointRecurrenceKind (RecurrenceKind)
@@ -8856,7 +8872,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
88568872 RecurKind RK = RdxDesc.getRecurrenceKind ();
88578873 if ((!RecurrenceDescriptor::isAnyOfRecurrenceKind (RK) &&
88588874 !RecurrenceDescriptor::isFindIVRecurrenceKind (RK) &&
8859- !RecurrenceDescriptor::isMinMaxRecurrenceKind (RK))) {
8875+ !RecurrenceDescriptor::isMinMaxRecurrenceKind (RK) &&
8876+ !RecurrenceDescriptor::isFindLastRecurrenceKind (RK))) {
88608877 VPBuilder PHBuilder (Plan->getVectorPreheader ());
88618878 VPValue *Iden = Plan->getOrAddLiveIn (
88628879 getRecurrenceIdentity (RK, PhiTy, RdxDesc.getFastMathFlags ()));
@@ -9970,6 +9987,22 @@ bool LoopVectorizePass::processLoop(Loop *L) {
99709987 // Override IC if user provided an interleave count.
99719988 IC = UserIC > 0 ? UserIC : IC;
99729989
9990+ // FIXME: Enable interleaving for last_active reductions.
9991+ if (any_of (LVL.getReductionVars (), [&](auto &Reduction) -> bool {
9992+ const RecurrenceDescriptor &RdxDesc = Reduction.second ;
9993+ return RecurrenceDescriptor::isFindLastRecurrenceKind (
9994+ RdxDesc.getRecurrenceKind ());
9995+ })) {
9996+ LLVM_DEBUG (dbgs () << " LV: Not interleaving without vectorization due "
9997+ << " to conditional scalar assignments.\n " );
9998+ IntDiagMsg = {
9999+ " ConditionalAssignmentPreventsScalarInterleaving" ,
10000+ " Unable to interleave without vectorization due to conditional "
10001+ " assignments" };
10002+ InterleaveLoop = false ;
10003+ IC = 1 ;
10004+ }
10005+
997310006 // Emit diagnostic messages, if any.
997410007 const char *VAPassName = Hints.vectorizeAnalysisPassName ();
997510008 if (!VectorizeLoop && !InterleaveLoop) {
0 commit comments