Skip to content

Commit 4989e20

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 8769119 commit 4989e20

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
@@ -4077,6 +4077,12 @@ class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
40774077
const VPCanonicalIVPHIRecipe *getCanonicalIV() const {
40784078
return const_cast<VPRegionBlock *>(this)->getCanonicalIV();
40794079
}
4080+
4081+
/// Return the type of the canonical IV for loop regions.
4082+
Type *getCanonicalIVType() { return getCanonicalIV()->getScalarType(); }
4083+
const Type *getCanonicalIVType() const {
4084+
return getCanonicalIV()->getScalarType();
4085+
}
40804086
};
40814087

40824088
inline VPRegionBlock *VPRecipeBase::getRegion() {

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,9 +2352,8 @@ bool VPWidenIntOrFpInductionRecipe::isCanonical() const {
23522352
return false;
23532353
auto *StepC = dyn_cast<ConstantInt>(getStepValue()->getLiveInIRValue());
23542354
auto *StartC = dyn_cast<ConstantInt>(getStartValue()->getLiveInIRValue());
2355-
auto *CanIV = getRegion()->getCanonicalIV();
23562355
return StartC && StartC->isZero() && StepC && StepC->isOne() &&
2357-
getScalarType() == CanIV->getScalarType();
2356+
getScalarType() == getRegion()->getCanonicalIVType();
23582357
}
23592358

23602359
#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
@@ -802,7 +802,7 @@ static VPValue *optimizeEarlyExitInductionUser(VPlan &Plan,
802802
// Calculate the final index.
803803
VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
804804
auto *CanonicalIV = LoopRegion->getCanonicalIV();
805-
Type *CanonicalIVType = CanonicalIV->getScalarType();
805+
Type *CanonicalIVType = LoopRegion->getCanonicalIVType();
806806
VPBuilder B(cast<VPBasicBlock>(PredVPBB));
807807

808808
DebugLoc DL = cast<VPInstruction>(Op)->getDebugLoc();
@@ -2382,8 +2382,8 @@ static VPActiveLaneMaskPHIRecipe *addVPLaneMaskPhiAndUpdateExitBranch(
23822382
"index.part.next");
23832383

23842384
// Create the active lane mask instruction in the VPlan preheader.
2385-
VPValue *ALMMultiplier = Plan.getOrAddLiveIn(
2386-
ConstantInt::get(TopRegion->getCanonicalIV()->getScalarType(), 1));
2385+
VPValue *ALMMultiplier =
2386+
Plan.getOrAddLiveIn(ConstantInt::get(TopRegion->getCanonicalIVType(), 1));
23872387
auto *EntryALM = Builder.createNaryOp(VPInstruction::ActiveLaneMask,
23882388
{EntryIncrement, TC, ALMMultiplier}, DL,
23892389
"active.lane.mask.entry");
@@ -2469,8 +2469,9 @@ void VPlanTransforms::addActiveLaneMask(
24692469
"UseActiveLaneMaskForControlFlow");
24702470

24712471
VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
2472-
auto *FoundWidenCanonicalIVUser = find_if(
2473-
LoopRegion->getCanonicalIV()->users(), IsaPred<VPWidenCanonicalIVRecipe>);
2472+
auto *CanonicalIV = LoopRegion->getCanonicalIV();
2473+
auto *FoundWidenCanonicalIVUser =
2474+
find_if(CanonicalIV->users(), IsaPred<VPWidenCanonicalIVRecipe>);
24742475
assert(FoundWidenCanonicalIVUser &&
24752476
"Must have widened canonical IV when tail folding!");
24762477
VPSingleDefRecipe *HeaderMask = findHeaderMask(Plan);
@@ -2483,7 +2484,7 @@ void VPlanTransforms::addActiveLaneMask(
24832484
} else {
24842485
VPBuilder B = VPBuilder::getToInsertAfter(WideCanonicalIV);
24852486
VPValue *ALMMultiplier = Plan.getOrAddLiveIn(
2486-
ConstantInt::get(LoopRegion->getCanonicalIV()->getScalarType(), 1));
2487+
ConstantInt::get(LoopRegion->getCanonicalIVType(), 1));
24872488
LaneMask =
24882489
B.createNaryOp(VPInstruction::ActiveLaneMask,
24892490
{WideCanonicalIV, Plan.getTripCount(), ALMMultiplier},
@@ -2755,7 +2756,7 @@ void VPlanTransforms::addExplicitVectorLength(
27552756
VPBasicBlock *Header = LoopRegion->getEntryBasicBlock();
27562757

27572758
auto *CanonicalIVPHI = LoopRegion->getCanonicalIV();
2758-
auto *CanIVTy = CanonicalIVPHI->getScalarType();
2759+
auto *CanIVTy = LoopRegion->getCanonicalIVType();
27592760
VPValue *StartV = CanonicalIVPHI->getStartValue();
27602761

27612762
// Create the ExplicitVectorLengthPhi recipe in the main loop.
@@ -4198,10 +4199,10 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
41984199
VPBuilder PHBuilder(Plan.getVectorPreheader());
41994200

42004201
VPValue *UF = Plan.getOrAddLiveIn(
4201-
ConstantInt::get(CanIV->getScalarType(), 1 * Plan.getUF()));
4202+
ConstantInt::get(VectorLoop->getCanonicalIVType(), 1 * Plan.getUF()));
42024203
if (VF.isScalable()) {
42034204
VPValue *VScale = PHBuilder.createElementCount(
4204-
CanIV->getScalarType(), ElementCount::getScalable(1));
4205+
VectorLoop->getCanonicalIVType(), ElementCount::getScalable(1));
42054206
VPValue *VScaleUF = PHBuilder.createNaryOp(Instruction::Mul, {VScale, UF});
42064207
Inc->setOperand(1, VScaleUF);
42074208
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)