Skip to content

Commit f70add4

Browse files
fhahnIanWood1
authored andcommitted
[VPlan] Handle VPIRPhi in VPRecipeBase::isPhi (NFC).
Also handle VPIRPhi in VPRecipeBase::isPhi, to simplify existing code dealing with VPIRPhis. Suggested as part of llvm#136455.
1 parent 652c5a3 commit f70add4

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9324,10 +9324,8 @@ static void addScalarResumePhis(VPRecipeBuilder &Builder, VPlan &Plan,
93249324
VPBuilder ScalarPHBuilder(ScalarPH);
93259325
VPValue *OneVPV = Plan.getOrAddLiveIn(
93269326
ConstantInt::get(Plan.getCanonicalIV()->getScalarType(), 1));
9327-
for (VPRecipeBase &ScalarPhiR : *Plan.getScalarHeader()) {
9328-
auto *ScalarPhiIRI = dyn_cast<VPIRPhi>(&ScalarPhiR);
9329-
if (!ScalarPhiIRI)
9330-
break;
9327+
for (VPRecipeBase &ScalarPhiR : Plan.getScalarHeader()->phis()) {
9328+
auto *ScalarPhiIRI = cast<VPIRPhi>(&ScalarPhiR);
93319329

93329330
// TODO: Extract final value from induction recipe initially, optimize to
93339331
// pre-computed end value together in optimizeInductionExitUsers.
@@ -9381,10 +9379,8 @@ collectUsersInExitBlocks(Loop *OrigLoop, VPRecipeBuilder &Builder,
93819379
if (ExitVPBB->getNumPredecessors() == 0)
93829380
continue;
93839381

9384-
for (VPRecipeBase &R : *ExitVPBB) {
9385-
auto *ExitIRI = dyn_cast<VPIRPhi>(&R);
9386-
if (!ExitIRI)
9387-
break;
9382+
for (VPRecipeBase &R : ExitVPBB->phis()) {
9383+
auto *ExitIRI = cast<VPIRPhi>(&R);
93889384
if (ExitVPBB->getSinglePredecessor() != Plan.getMiddleBlock()) {
93899385
assert(ExitIRI->getNumOperands() ==
93909386
ExitVPBB->getPredecessors().size() &&
@@ -10579,10 +10575,9 @@ static void preparePlanForMainVectorLoop(VPlan &MainPlan, VPlan &EpiPlan) {
1057910575
EpiWidenedPhis.insert(
1058010576
cast<PHINode>(R.getVPSingleValue()->getUnderlyingValue()));
1058110577
}
10582-
for (VPRecipeBase &R : make_early_inc_range(*MainPlan.getScalarHeader())) {
10583-
auto *VPIRInst = dyn_cast<VPIRPhi>(&R);
10584-
if (!VPIRInst)
10585-
break;
10578+
for (VPRecipeBase &R :
10579+
make_early_inc_range(MainPlan.getScalarHeader()->phis())) {
10580+
auto *VPIRInst = cast<VPIRPhi>(&R);
1058610581
if (EpiWidenedPhis.contains(&VPIRInst->getIRPhi()))
1058710582
continue;
1058810583
// There is no corresponding wide induction in the epilogue plan that would

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ InstructionCost VPRecipeBase::computeCost(ElementCount VF,
274274
bool VPRecipeBase::isPhi() const {
275275
return (getVPDefID() >= VPFirstPHISC && getVPDefID() <= VPLastPHISC) ||
276276
(isa<VPInstruction>(this) &&
277-
cast<VPInstruction>(this)->getOpcode() == Instruction::PHI);
277+
cast<VPInstruction>(this)->getOpcode() == Instruction::PHI) ||
278+
isa<VPIRPhi>(this);
278279
}
279280

280281
bool VPRecipeBase::isScalarCast() const {

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -874,10 +874,8 @@ void VPlanTransforms::optimizeInductionExitUsers(
874874
VPBlockBase *MiddleVPBB = Plan.getMiddleBlock();
875875
VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType());
876876
for (VPIRBasicBlock *ExitVPBB : Plan.getExitBlocks()) {
877-
for (VPRecipeBase &R : *ExitVPBB) {
878-
auto *ExitIRI = dyn_cast<VPIRPhi>(&R);
879-
if (!ExitIRI)
880-
break;
877+
for (VPRecipeBase &R : ExitVPBB->phis()) {
878+
auto *ExitIRI = cast<VPIRPhi>(&R);
881879

882880
for (auto [Idx, PredVPBB] : enumerate(ExitVPBB->getPredecessors())) {
883881
VPValue *Escape = nullptr;
@@ -2505,11 +2503,8 @@ void VPlanTransforms::handleUncountableEarlyExit(
25052503
// Update the exit phis in the early exit block.
25062504
VPBuilder MiddleBuilder(NewMiddle);
25072505
VPBuilder EarlyExitB(VectorEarlyExitVPBB);
2508-
for (VPRecipeBase &R : *VPEarlyExitBlock) {
2509-
auto *ExitIRI = dyn_cast<VPIRPhi>(&R);
2510-
if (!ExitIRI)
2511-
break;
2512-
2506+
for (VPRecipeBase &R : VPEarlyExitBlock->phis()) {
2507+
auto *ExitIRI = cast<VPIRPhi>(&R);
25132508
PHINode &ExitPhi = ExitIRI->getIRPhi();
25142509
VPValue *IncomingFromEarlyExit = RecipeBuilder.getVPValueOrAddLiveIn(
25152510
ExitPhi.getIncomingValueForBlock(UncountableExitingBlock));

0 commit comments

Comments
 (0)