Skip to content

Commit 9736ed5

Browse files
committed
[VPlan] Add getCanonicalIVType (NFC).
Split off from llvm#156262. Similar to VPRegionBlock::getCanonicalIV, add helper to get the type of the canonical IV, in preparation for removing VPCanonicalIVPHIRecipe.
1 parent 792c65c commit 9736ed5

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4103,6 +4103,12 @@ class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
41034103
const VPCanonicalIVPHIRecipe *getCanonicalIV() const {
41044104
return const_cast<VPRegionBlock *>(this)->getCanonicalIV();
41054105
}
4106+
4107+
/// Return the type of the canonical IV for loop regions.
4108+
Type *getCanonicalIVType() { return getCanonicalIV()->getScalarType(); }
4109+
const Type *getCanonicalIVType() const {
4110+
return getCanonicalIV()->getScalarType();
4111+
}
41064112
};
41074113

41084114
inline VPRegionBlock *VPRecipeBase::getRegion() {

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,9 +2368,8 @@ bool VPWidenIntOrFpInductionRecipe::isCanonical() const {
23682368
return false;
23692369
auto *StepC = dyn_cast<ConstantInt>(getStepValue()->getLiveInIRValue());
23702370
auto *StartC = dyn_cast<ConstantInt>(getStartValue()->getLiveInIRValue());
2371-
auto *CanIV = getRegion()->getCanonicalIV();
23722371
return StartC && StartC->isZero() && StepC && StepC->isOne() &&
2373-
getScalarType() == CanIV->getScalarType();
2372+
getScalarType() == getRegion()->getCanonicalIVType();
23742373
}
23752374

23762375
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ static VPValue *optimizeEarlyExitInductionUser(VPlan &Plan,
801801
// Calculate the final index.
802802
VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
803803
auto *CanonicalIV = LoopRegion->getCanonicalIV();
804-
Type *CanonicalIVType = CanonicalIV->getScalarType();
804+
Type *CanonicalIVType = LoopRegion->getCanonicalIVType();
805805
VPBuilder B(cast<VPBasicBlock>(PredVPBB));
806806

807807
DebugLoc DL = cast<VPInstruction>(Op)->getDebugLoc();
@@ -2404,8 +2404,8 @@ static VPActiveLaneMaskPHIRecipe *addVPLaneMaskPhiAndUpdateExitBranch(
24042404
"index.part.next");
24052405

24062406
// Create the active lane mask instruction in the VPlan preheader.
2407-
VPValue *ALMMultiplier = Plan.getOrAddLiveIn(
2408-
ConstantInt::get(TopRegion->getCanonicalIV()->getScalarType(), 1));
2407+
VPValue *ALMMultiplier =
2408+
Plan.getOrAddLiveIn(ConstantInt::get(TopRegion->getCanonicalIVType(), 1));
24092409
auto *EntryALM = Builder.createNaryOp(VPInstruction::ActiveLaneMask,
24102410
{EntryIncrement, TC, ALMMultiplier}, DL,
24112411
"active.lane.mask.entry");
@@ -2491,8 +2491,9 @@ void VPlanTransforms::addActiveLaneMask(
24912491
"UseActiveLaneMaskForControlFlow");
24922492

24932493
VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
2494-
auto *FoundWidenCanonicalIVUser = find_if(
2495-
LoopRegion->getCanonicalIV()->users(), IsaPred<VPWidenCanonicalIVRecipe>);
2494+
auto *CanonicalIV = LoopRegion->getCanonicalIV();
2495+
auto *FoundWidenCanonicalIVUser =
2496+
find_if(CanonicalIV->users(), IsaPred<VPWidenCanonicalIVRecipe>);
24962497
assert(FoundWidenCanonicalIVUser &&
24972498
"Must have widened canonical IV when tail folding!");
24982499
VPSingleDefRecipe *HeaderMask = findHeaderMask(Plan);
@@ -2505,7 +2506,7 @@ void VPlanTransforms::addActiveLaneMask(
25052506
} else {
25062507
VPBuilder B = VPBuilder::getToInsertAfter(WideCanonicalIV);
25072508
VPValue *ALMMultiplier = Plan.getOrAddLiveIn(
2508-
ConstantInt::get(LoopRegion->getCanonicalIV()->getScalarType(), 1));
2509+
ConstantInt::get(LoopRegion->getCanonicalIVType(), 1));
25092510
LaneMask =
25102511
B.createNaryOp(VPInstruction::ActiveLaneMask,
25112512
{WideCanonicalIV, Plan.getTripCount(), ALMMultiplier},
@@ -2777,7 +2778,7 @@ void VPlanTransforms::addExplicitVectorLength(
27772778
VPBasicBlock *Header = LoopRegion->getEntryBasicBlock();
27782779

27792780
auto *CanonicalIVPHI = LoopRegion->getCanonicalIV();
2780-
auto *CanIVTy = CanonicalIVPHI->getScalarType();
2781+
auto *CanIVTy = LoopRegion->getCanonicalIVType();
27812782
VPValue *StartV = CanonicalIVPHI->getStartValue();
27822783

27832784
// Create the ExplicitVectorLengthPhi recipe in the main loop.
@@ -4295,10 +4296,10 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
42954296
VPBuilder PHBuilder(Plan.getVectorPreheader());
42964297

42974298
VPValue *UF = Plan.getOrAddLiveIn(
4298-
ConstantInt::get(CanIV->getScalarType(), 1 * Plan.getUF()));
4299+
ConstantInt::get(VectorLoop->getCanonicalIVType(), 1 * Plan.getUF()));
42994300
if (VF.isScalable()) {
43004301
VPValue *VScale = PHBuilder.createElementCount(
4301-
CanIV->getScalarType(), ElementCount::getScalable(1));
4302+
VectorLoop->getCanonicalIVType(), ElementCount::getScalable(1));
43024303
VPValue *VScaleUF = PHBuilder.createNaryOp(Instruction::Mul, {VScale, UF});
43034304
Inc->setOperand(1, VScaleUF);
43044305
Plan.getVF().replaceAllUsesWith(VScale);

llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ class UnrollState {
6969
VPBasicBlock::iterator InsertPtForPhi);
7070

7171
VPValue *getConstantVPV(unsigned Part) {
72-
Type *CanIVIntTy =
73-
Plan.getVectorLoopRegion()->getCanonicalIV()->getScalarType();
72+
Type *CanIVIntTy = Plan.getVectorLoopRegion()->getCanonicalIVType();
7473
return Plan.getOrAddLiveIn(ConstantInt::get(CanIVIntTy, Part));
7574
}
7675

0 commit comments

Comments
 (0)