Skip to content

Commit 87939bd

Browse files
fhahngithub-actions[bot]
authored andcommitted
Automerge: [VPlan] Add VPRegionBlock::getCanonicalIVType (NFC). (#164127)
Split off from llvm/llvm-project#156262. Similar to VPRegionBlock::getCanonicalIV, add helper to get the type of the canonical IV, in preparation for removing VPCanonicalIVPHIRecipe. PR: llvm/llvm-project#164127
2 parents 492cc9b + a943132 commit 87939bd

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4109,6 +4109,12 @@ class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
41094109
const VPCanonicalIVPHIRecipe *getCanonicalIV() const {
41104110
return const_cast<VPRegionBlock *>(this)->getCanonicalIV();
41114111
}
4112+
4113+
/// Return the type of the canonical IV for loop regions.
4114+
Type *getCanonicalIVType() { return getCanonicalIV()->getScalarType(); }
4115+
const Type *getCanonicalIVType() const {
4116+
return getCanonicalIV()->getScalarType();
4117+
}
41124118
};
41134119

41144120
inline VPRegionBlock *VPRecipeBase::getRegion() {

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,9 +2372,8 @@ bool VPWidenIntOrFpInductionRecipe::isCanonical() const {
23722372
return false;
23732373
auto *StepC = dyn_cast<ConstantInt>(getStepValue()->getLiveInIRValue());
23742374
auto *StartC = dyn_cast<ConstantInt>(getStartValue()->getLiveInIRValue());
2375-
auto *CanIV = getRegion()->getCanonicalIV();
23762375
return StartC && StartC->isZero() && StepC && StepC->isOne() &&
2377-
getScalarType() == CanIV->getScalarType();
2376+
getScalarType() == getRegion()->getCanonicalIVType();
23782377
}
23792378

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

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ static VPValue *optimizeEarlyExitInductionUser(VPlan &Plan,
820820
// Calculate the final index.
821821
VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
822822
auto *CanonicalIV = LoopRegion->getCanonicalIV();
823-
Type *CanonicalIVType = CanonicalIV->getScalarType();
823+
Type *CanonicalIVType = LoopRegion->getCanonicalIVType();
824824
VPBuilder B(cast<VPBasicBlock>(PredVPBB));
825825

826826
DebugLoc DL = cast<VPInstruction>(Op)->getDebugLoc();
@@ -2402,8 +2402,8 @@ static VPActiveLaneMaskPHIRecipe *addVPLaneMaskPhiAndUpdateExitBranch(
24022402
"index.part.next");
24032403

24042404
// Create the active lane mask instruction in the VPlan preheader.
2405-
VPValue *ALMMultiplier = Plan.getOrAddLiveIn(
2406-
ConstantInt::get(TopRegion->getCanonicalIV()->getScalarType(), 1));
2405+
VPValue *ALMMultiplier =
2406+
Plan.getOrAddLiveIn(ConstantInt::get(TopRegion->getCanonicalIVType(), 1));
24072407
auto *EntryALM = Builder.createNaryOp(VPInstruction::ActiveLaneMask,
24082408
{EntryIncrement, TC, ALMMultiplier}, DL,
24092409
"active.lane.mask.entry");
@@ -2503,7 +2503,7 @@ void VPlanTransforms::addActiveLaneMask(
25032503
} else {
25042504
VPBuilder B = VPBuilder::getToInsertAfter(WideCanonicalIV);
25052505
VPValue *ALMMultiplier = Plan.getOrAddLiveIn(
2506-
ConstantInt::get(LoopRegion->getCanonicalIV()->getScalarType(), 1));
2506+
ConstantInt::get(LoopRegion->getCanonicalIVType(), 1));
25072507
LaneMask =
25082508
B.createNaryOp(VPInstruction::ActiveLaneMask,
25092509
{WideCanonicalIV, Plan.getTripCount(), ALMMultiplier},
@@ -2775,7 +2775,7 @@ void VPlanTransforms::addExplicitVectorLength(
27752775
VPBasicBlock *Header = LoopRegion->getEntryBasicBlock();
27762776

27772777
auto *CanonicalIVPHI = LoopRegion->getCanonicalIV();
2778-
auto *CanIVTy = CanonicalIVPHI->getScalarType();
2778+
auto *CanIVTy = LoopRegion->getCanonicalIVType();
27792779
VPValue *StartV = CanonicalIVPHI->getStartValue();
27802780

27812781
// Create the ExplicitVectorLengthPhi recipe in the main loop.
@@ -4336,10 +4336,10 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
43364336
VPBuilder PHBuilder(Plan.getVectorPreheader());
43374337

43384338
VPValue *UF = Plan.getOrAddLiveIn(
4339-
ConstantInt::get(CanIV->getScalarType(), 1 * Plan.getUF()));
4339+
ConstantInt::get(VectorLoop->getCanonicalIVType(), 1 * Plan.getUF()));
43404340
if (VF.isScalable()) {
43414341
VPValue *VScale = PHBuilder.createElementCount(
4342-
CanIV->getScalarType(), ElementCount::getScalable(1));
4342+
VectorLoop->getCanonicalIVType(), ElementCount::getScalable(1));
43434343
VPValue *VScaleUF = PHBuilder.createNaryOp(Instruction::Mul, {VScale, UF});
43444344
Inc->setOperand(1, VScaleUF);
43454345
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)