Skip to content

Commit 7f4e36e

Browse files
committed
[VPlan] Create PHI VPInstruction using VPBuilder (NFC).
Use builder to create scalar PHI VPInstructions.
1 parent 79bc8ad commit 7f4e36e

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ class VPBuilder {
249249
new VPInstruction(Ptr, Offset, GEPNoWrapFlags::inBounds(), DL, Name));
250250
}
251251

252+
VPInstruction *createScalarPhi(ArrayRef<VPValue *> IncomingValues,
253+
DebugLoc DL, const Twine &Name = "") {
254+
return tryInsertInstruction(
255+
new VPInstruction(Instruction::PHI, IncomingValues, DL, Name));
256+
}
257+
252258
/// Convert the input value \p Current to the corresponding value of an
253259
/// induction with \p Start and \p Step values, using \p Start + \p Current *
254260
/// \p Step.

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,17 +2093,16 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
20932093
// TODO: Use VPInstruction::ExplicitVectorLength to get maximum EVL.
20942094
VPValue *MaxEVL = &Plan.getVF();
20952095
// Emit VPScalarCastRecipe in preheader if VF is not a 32 bits integer.
2096+
VPBuilder Builder(LoopRegion->getPreheaderVPBB());
20962097
if (unsigned VFSize =
20972098
TypeInfo.inferScalarType(MaxEVL)->getScalarSizeInBits();
20982099
VFSize != 32) {
2099-
VPBuilder Builder(LoopRegion->getPreheaderVPBB());
21002100
MaxEVL = Builder.createScalarCast(
21012101
VFSize > 32 ? Instruction::Trunc : Instruction::ZExt, MaxEVL,
21022102
Type::getInt32Ty(Ctx), DebugLoc());
21032103
}
2104-
PrevEVL = new VPInstruction(Instruction::PHI, {MaxEVL, &EVL}, DebugLoc(),
2105-
"prev.evl");
2106-
PrevEVL->insertBefore(*Header, Header->getFirstNonPhi());
2104+
Builder.setInsertPoint(Header, Header->getFirstNonPhi());
2105+
PrevEVL = Builder.createScalarPhi({MaxEVL, &EVL}, DebugLoc(), "prev.evl");
21072106
}
21082107

21092108
for (VPUser *U : to_vector(Plan.getVF().users())) {
@@ -2433,10 +2432,10 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
24332432
auto *PhiR = cast<VPHeaderPHIRecipe>(&R);
24342433
StringRef Name =
24352434
isa<VPCanonicalIVPHIRecipe>(PhiR) ? "index" : "evl.based.iv";
2436-
auto *ScalarR = new VPInstruction(
2437-
Instruction::PHI, {PhiR->getStartValue(), PhiR->getBackedgeValue()},
2435+
VPBuilder Builder(PhiR);
2436+
auto *ScalarR = Builder.createScalarPhi(
2437+
{PhiR->getStartValue(), PhiR->getBackedgeValue()},
24382438
PhiR->getDebugLoc(), Name);
2439-
ScalarR->insertBefore(PhiR);
24402439
PhiR->replaceAllUsesWith(ScalarR);
24412440
ToRemove.push_back(PhiR);
24422441
continue;

0 commit comments

Comments
 (0)