@@ -501,7 +501,8 @@ static void removeRedundantInductionCasts(VPlan &Plan) {
501501// / Try to replace VPWidenCanonicalIVRecipes with a widened canonical IV
502502// / recipe, if it exists.
503503static void removeRedundantCanonicalIVs (VPlan &Plan) {
504- VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV ();
504+ VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion ();
505+ VPCanonicalIVPHIRecipe *CanonicalIV = LoopRegion->getCanonicalIV ();
505506 VPWidenCanonicalIVRecipe *WidenNewIV = nullptr ;
506507 for (VPUser *U : CanonicalIV->users ()) {
507508 WidenNewIV = dyn_cast<VPWidenCanonicalIVRecipe>(U);
@@ -512,7 +513,7 @@ static void removeRedundantCanonicalIVs(VPlan &Plan) {
512513 if (!WidenNewIV)
513514 return ;
514515
515- VPBasicBlock *HeaderVPBB = Plan. getVectorLoopRegion () ->getEntryBasicBlock ();
516+ VPBasicBlock *HeaderVPBB = LoopRegion ->getEntryBasicBlock ();
516517 for (VPRecipeBase &Phi : HeaderVPBB->phis ()) {
517518 auto *WidenOriginalIV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&Phi);
518519
@@ -582,8 +583,9 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
582583 FPMathOperator *FPBinOp, Instruction *TruncI,
583584 VPValue *StartV, VPValue *Step, DebugLoc DL,
584585 VPBuilder &Builder) {
585- VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion ()->getEntryBasicBlock ();
586- VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV ();
586+ VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion ();
587+ VPBasicBlock *HeaderVPBB = LoopRegion->getEntryBasicBlock ();
588+ VPCanonicalIVPHIRecipe *CanonicalIV = LoopRegion->getCanonicalIV ();
587589 VPSingleDefRecipe *BaseIV = Builder.createDerivedIV (
588590 Kind, FPBinOp, StartV, CanonicalIV, Step, " offset.idx" );
589591
@@ -800,8 +802,9 @@ static VPValue *optimizeEarlyExitInductionUser(VPlan &Plan,
800802 return nullptr ;
801803
802804 // Calculate the final index.
803- VPValue *EndValue = Plan.getCanonicalIV ();
804- auto CanonicalIVType = Plan.getCanonicalIV ()->getScalarType ();
805+ VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion ();
806+ auto *CanonicalIV = LoopRegion->getCanonicalIV ();
807+ Type *CanonicalIVType = CanonicalIV->getScalarType ();
805808 VPBuilder B (cast<VPBasicBlock>(PredVPBB));
806809
807810 DebugLoc DL = cast<VPInstruction>(Op)->getDebugLoc ();
@@ -810,7 +813,8 @@ static VPValue *optimizeEarlyExitInductionUser(VPlan &Plan,
810813 Type *FirstActiveLaneType = TypeInfo.inferScalarType (FirstActiveLane);
811814 FirstActiveLane = B.createScalarZExtOrTrunc (FirstActiveLane, CanonicalIVType,
812815 FirstActiveLaneType, DL);
813- EndValue = B.createNaryOp (Instruction::Add, {EndValue, FirstActiveLane}, DL);
816+ VPValue *EndValue =
817+ B.createNaryOp (Instruction::Add, {CanonicalIV, FirstActiveLane}, DL);
814818
815819 // `getOptimizableIVOf()` always returns the pre-incremented IV, so if it
816820 // changed it means the exit is using the incremented value, so we need to
@@ -1530,7 +1534,7 @@ static bool isConditionTrueViaVFAndUF(VPValue *Cond, VPlan &Plan,
15301534 return isConditionTrueViaVFAndUF (C, Plan, BestVF, BestUF, SE);
15311535 });
15321536
1533- auto *CanIV = Plan.getCanonicalIV ();
1537+ auto *CanIV = Plan.getVectorLoopRegion ()-> getCanonicalIV ();
15341538 if (!match (Cond, m_SpecificICmp (CmpInst::ICMP_EQ,
15351539 m_Specific (CanIV->getBackedgeValue ()),
15361540 m_Specific (&Plan.getVectorTripCount ()))))
@@ -2319,7 +2323,7 @@ static VPActiveLaneMaskPHIRecipe *addVPLaneMaskPhiAndUpdateExitBranch(
23192323 VPlan &Plan, bool DataAndControlFlowWithoutRuntimeCheck) {
23202324 VPRegionBlock *TopRegion = Plan.getVectorLoopRegion ();
23212325 VPBasicBlock *EB = TopRegion->getExitingBasicBlock ();
2322- auto *CanonicalIVPHI = Plan. getCanonicalIV ();
2326+ auto *CanonicalIVPHI = TopRegion-> getCanonicalIV ();
23232327 VPValue *StartV = CanonicalIVPHI->getStartValue ();
23242328
23252329 auto *CanonicalIVIncrement =
@@ -2358,7 +2362,7 @@ static VPActiveLaneMaskPHIRecipe *addVPLaneMaskPhiAndUpdateExitBranch(
23582362
23592363 // Create the active lane mask instruction in the VPlan preheader.
23602364 VPValue *ALMMultiplier = Plan.getOrAddLiveIn (
2361- ConstantInt::get (Plan. getCanonicalIV ()->getScalarType (), 1 ));
2365+ ConstantInt::get (TopRegion-> getCanonicalIV ()->getScalarType (), 1 ));
23622366 auto *EntryALM = Builder.createNaryOp (VPInstruction::ActiveLaneMask,
23632367 {EntryIncrement, TC, ALMMultiplier}, DL,
23642368 " active.lane.mask.entry" );
@@ -2394,21 +2398,23 @@ static VPActiveLaneMaskPHIRecipe *addVPLaneMaskPhiAndUpdateExitBranch(
23942398// / TODO: Introduce explicit recipe for header-mask instead of searching
23952399// / for the header-mask pattern manually.
23962400static VPSingleDefRecipe *findHeaderMask (VPlan &Plan) {
2401+ VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion ();
23972402 SmallVector<VPValue *> WideCanonicalIVs;
2398- auto *FoundWidenCanonicalIVUser = find_if (Plan. getCanonicalIV ()-> users (),
2399- IsaPred<VPWidenCanonicalIVRecipe>);
2400- assert (count_if (Plan. getCanonicalIV ()->users (),
2403+ auto *FoundWidenCanonicalIVUser = find_if (
2404+ LoopRegion-> getCanonicalIV ()-> users (), IsaPred<VPWidenCanonicalIVRecipe>);
2405+ assert (count_if (LoopRegion-> getCanonicalIV ()->users (),
24012406 IsaPred<VPWidenCanonicalIVRecipe>) <= 1 &&
24022407 " Must have at most one VPWideCanonicalIVRecipe" );
2403- if (FoundWidenCanonicalIVUser != Plan.getCanonicalIV ()->users ().end ()) {
2408+ if (FoundWidenCanonicalIVUser !=
2409+ LoopRegion->getCanonicalIV ()->users ().end ()) {
24042410 auto *WideCanonicalIV =
24052411 cast<VPWidenCanonicalIVRecipe>(*FoundWidenCanonicalIVUser);
24062412 WideCanonicalIVs.push_back (WideCanonicalIV);
24072413 }
24082414
24092415 // Also include VPWidenIntOrFpInductionRecipes that represent a widened
24102416 // version of the canonical induction.
2411- VPBasicBlock *HeaderVPBB = Plan. getVectorLoopRegion () ->getEntryBasicBlock ();
2417+ VPBasicBlock *HeaderVPBB = LoopRegion ->getEntryBasicBlock ();
24122418 for (VPRecipeBase &Phi : HeaderVPBB->phis ()) {
24132419 auto *WidenOriginalIV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&Phi);
24142420 if (WidenOriginalIV && WidenOriginalIV->isCanonical ())
@@ -2441,8 +2447,9 @@ void VPlanTransforms::addActiveLaneMask(
24412447 " DataAndControlFlowWithoutRuntimeCheck implies "
24422448 " UseActiveLaneMaskForControlFlow" );
24432449
2444- auto *FoundWidenCanonicalIVUser = find_if (Plan.getCanonicalIV ()->users (),
2445- IsaPred<VPWidenCanonicalIVRecipe>);
2450+ VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion ();
2451+ auto *FoundWidenCanonicalIVUser = find_if (
2452+ LoopRegion->getCanonicalIV ()->users (), IsaPred<VPWidenCanonicalIVRecipe>);
24462453 assert (FoundWidenCanonicalIVUser &&
24472454 " Must have widened canonical IV when tail folding!" );
24482455 VPSingleDefRecipe *HeaderMask = findHeaderMask (Plan);
@@ -2455,7 +2462,7 @@ void VPlanTransforms::addActiveLaneMask(
24552462 } else {
24562463 VPBuilder B = VPBuilder::getToInsertAfter (WideCanonicalIV);
24572464 VPValue *ALMMultiplier = Plan.getOrAddLiveIn (
2458- ConstantInt::get (Plan. getCanonicalIV ()->getScalarType (), 1 ));
2465+ ConstantInt::get (LoopRegion-> getCanonicalIV ()->getScalarType (), 1 ));
24592466 LaneMask =
24602467 B.createNaryOp (VPInstruction::ActiveLaneMask,
24612468 {WideCanonicalIV, Plan.getTripCount (), ALMMultiplier},
@@ -2565,9 +2572,10 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
25652572 });
25662573
25672574 assert (all_of (Plan.getVFxUF ().users (),
2568- [&Plan](VPUser *U) {
2569- return match (U, m_c_Add (m_Specific (Plan.getCanonicalIV ()),
2570- m_Specific (&Plan.getVFxUF ()))) ||
2575+ [&LoopRegion, &Plan](VPUser *U) {
2576+ return match (U,
2577+ m_c_Add (m_Specific (LoopRegion->getCanonicalIV ()),
2578+ m_Specific (&Plan.getVFxUF ()))) ||
25712579 isa<VPWidenPointerInductionRecipe>(U);
25722580 }) &&
25732581 " Only users of VFxUF should be VPWidenPointerInductionRecipe and the "
@@ -2722,9 +2730,10 @@ void VPlanTransforms::addExplicitVectorLength(
27222730 VPlan &Plan, const std::optional<unsigned > &MaxSafeElements) {
27232731 if (Plan.hasScalarVFOnly ())
27242732 return ;
2725- VPBasicBlock *Header = Plan.getVectorLoopRegion ()->getEntryBasicBlock ();
2733+ VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion ();
2734+ VPBasicBlock *Header = LoopRegion->getEntryBasicBlock ();
27262735
2727- auto *CanonicalIVPHI = Plan. getCanonicalIV ();
2736+ auto *CanonicalIVPHI = LoopRegion-> getCanonicalIV ();
27282737 auto *CanIVTy = CanonicalIVPHI->getScalarType ();
27292738 VPValue *StartV = CanonicalIVPHI->getStartValue ();
27302739
@@ -4164,7 +4173,7 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
41644173
41654174 // Adjust induction to reflect that the transformed plan only processes one
41664175 // original iteration.
4167- auto *CanIV = Plan. getCanonicalIV ();
4176+ auto *CanIV = VectorLoop-> getCanonicalIV ();
41684177 auto *Inc = cast<VPInstruction>(CanIV->getBackedgeValue ());
41694178 VPBuilder PHBuilder (Plan.getVectorPreheader ());
41704179
0 commit comments