Skip to content

Commit b2d70e8

Browse files
committed
[VPlan] Use Builder to create cast recipes in VPlanTransforms (NFC).
Use VPBuilder in a few more places. This avoids manual insertions and will make changing the cast recipe easier in the future.
1 parent 22d8ba3 commit b2d70e8

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,11 +1748,10 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
17481748
if (unsigned VFSize =
17491749
TypeInfo.inferScalarType(MaxEVL)->getScalarSizeInBits();
17501750
VFSize != 32) {
1751-
MaxEVL = new VPScalarCastRecipe(
1751+
VPBuilder Builder(LoopRegion->getPreheaderVPBB());
1752+
MaxEVL = Builder.createScalarCast(
17521753
VFSize > 32 ? Instruction::Trunc : Instruction::ZExt, MaxEVL,
17531754
Type::getInt32Ty(Ctx), DebugLoc());
1754-
VPBasicBlock *Preheader = LoopRegion->getPreheaderVPBB();
1755-
Preheader->appendRecipe(cast<VPScalarCastRecipe>(MaxEVL));
17561755
}
17571756
PrevEVL = new VPScalarPHIRecipe(MaxEVL, &EVL, DebugLoc(), "prev.evl");
17581757
PrevEVL->insertBefore(*Header, Header->getFirstNonPhi());
@@ -1872,20 +1871,19 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
18721871

18731872
auto *CanonicalIVIncrement =
18741873
cast<VPInstruction>(CanonicalIVPHI->getBackedgeValue());
1874+
Builder.setInsertPoint(CanonicalIVIncrement);
18751875
VPSingleDefRecipe *OpVPEVL = VPEVL;
18761876
if (unsigned IVSize = CanonicalIVPHI->getScalarType()->getScalarSizeInBits();
18771877
IVSize != 32) {
1878-
OpVPEVL = new VPScalarCastRecipe(
1878+
OpVPEVL = Builder.createScalarCast(
18791879
IVSize < 32 ? Instruction::Trunc : Instruction::ZExt, OpVPEVL,
18801880
CanonicalIVPHI->getScalarType(), CanonicalIVIncrement->getDebugLoc());
1881-
OpVPEVL->insertBefore(CanonicalIVIncrement);
18821881
}
1883-
auto *NextEVLIV =
1884-
new VPInstruction(Instruction::Add, {OpVPEVL, EVLPhi},
1885-
{CanonicalIVIncrement->hasNoUnsignedWrap(),
1886-
CanonicalIVIncrement->hasNoSignedWrap()},
1887-
CanonicalIVIncrement->getDebugLoc(), "index.evl.next");
1888-
NextEVLIV->insertBefore(CanonicalIVIncrement);
1882+
auto *NextEVLIV = Builder.createOverflowingOp(
1883+
Instruction::Add, {OpVPEVL, EVLPhi},
1884+
{CanonicalIVIncrement->hasNoUnsignedWrap(),
1885+
CanonicalIVIncrement->hasNoSignedWrap()},
1886+
CanonicalIVIncrement->getDebugLoc(), "index.evl.next");
18891887
EVLPhi->addOperand(NextEVLIV);
18901888

18911889
transformRecipestoEVLRecipes(Plan, *VPEVL);

0 commit comments

Comments
 (0)