[llvm] 1faa9f7 - [VPlan] Infer SrcTy in createScalarExtOrTrunc (NFC) (#210423)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 18 04:14:33 PDT 2026
Author: Ramkumar Ramachandra
Date: 2026-07-18T11:14:28Z
New Revision: 1faa9f73119f007583ca829e07d78e82a40f1bae
URL: https://github.com/llvm/llvm-project/commit/1faa9f73119f007583ca829e07d78e82a40f1bae
DIFF: https://github.com/llvm/llvm-project/commit/1faa9f73119f007583ca829e07d78e82a40f1bae.diff
LOG: [VPlan] Infer SrcTy in createScalarExtOrTrunc (NFC) (#210423)
The argument is redundant and can be inferred from Op.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
index cd02ced2942d1..ed02d9475fc6f 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
@@ -453,8 +453,8 @@ class VPBuilder {
return createScalarIntrinsic(Intrinsic::vscale, {}, ResultTy, DL);
}
- VPValue *createScalarZExtOrTrunc(VPValue *Op, Type *ResultTy, Type *SrcTy,
- DebugLoc DL) {
+ VPValue *createScalarZExtOrTrunc(VPValue *Op, Type *ResultTy, DebugLoc DL) {
+ Type *SrcTy = Op->getScalarType();
if (ResultTy == SrcTy)
return Op;
Instruction::CastOps CastOp =
@@ -464,8 +464,8 @@ class VPBuilder {
return createScalarCast(CastOp, Op, ResultTy, DL);
}
- VPValue *createScalarSExtOrTrunc(VPValue *Op, Type *ResultTy, Type *SrcTy,
- DebugLoc DL) {
+ VPValue *createScalarSExtOrTrunc(VPValue *Op, Type *ResultTy, DebugLoc DL) {
+ Type *SrcTy = Op->getScalarType();
if (ResultTy == SrcTy)
return Op;
Instruction::CastOps CastOp =
diff --git a/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp b/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp
index e2e564b6afbbf..cc55d766ba596 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanEVLTailFolding.cpp
@@ -45,8 +45,7 @@ bool VPlanTransforms::simplifyKnownEVL(VPlan &Plan, ElementCount VF,
continue;
VPValue *Trunc = VPBuilder(&R).createScalarZExtOrTrunc(
- AVL, Type::getInt32Ty(Plan.getContext()), AVLSCEV->getType(),
- R.getDebugLoc());
+ AVL, Type::getInt32Ty(Plan.getContext()), R.getDebugLoc());
if (Trunc != AVL) {
auto *TruncR = cast<VPSingleDefRecipe>(Trunc);
const DataLayout &DL = Plan.getDataLayout();
@@ -118,7 +117,7 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
EVLEndPtr->insertBefore(&CurRecipe);
// Cast EVL (i32) to match the VF operand's type.
VPValue *EVLAsVF = VPBuilder(EVLEndPtr).createScalarZExtOrTrunc(
- &EVL, EVLEndPtr->getOperand(1)->getScalarType(), EVL.getScalarType(),
+ &EVL, EVLEndPtr->getOperand(1)->getScalarType(),
DebugLoc::getUnknown());
EVLEndPtr->setOperand(1, EVLAsVF);
return EVLEndPtr;
@@ -208,9 +207,7 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
if (match(&CurRecipe, m_LastActiveLane(m_Specific(HeaderMask)))) {
Type *Ty = CurRecipe.getVPSingleValue()->getScalarType();
- VPValue *ZExt =
- VPBuilder(&CurRecipe)
- .createScalarZExtOrTrunc(&EVL, Ty, EVL.getScalarType(), DL);
+ VPValue *ZExt = VPBuilder(&CurRecipe).createScalarZExtOrTrunc(&EVL, Ty, DL);
return new VPInstruction(
Instruction::Sub, {ZExt, Plan->getConstantInt(Ty, 1)},
VPIRFlags::getDefaultFlags(Instruction::Sub), {}, DL);
@@ -353,7 +350,7 @@ static void fixupVFUsersForEVL(VPlan &Plan, VPValue &EVL) {
VPValue *EVLAsIdx =
VPBuilder::getToInsertAfter(EVL.getDefiningRecipe())
.createScalarZExtOrTrunc(&EVL, Plan.getVF().getScalarType(),
- EVL.getScalarType(), DebugLoc::getUnknown());
+ DebugLoc::getUnknown());
assert(all_of(Plan.getVF().users(),
[&Plan](VPUser *U) {
@@ -394,8 +391,7 @@ static void fixupVFUsersForEVL(VPlan &Plan, VPValue &EVL) {
// Emit VPScalarCastRecipe in preheader if VF is not a 32 bits integer.
VPBuilder Builder(LoopRegion->getPreheaderVPBB());
MaxEVL = Builder.createScalarZExtOrTrunc(
- MaxEVL, Type::getInt32Ty(Plan.getContext()), MaxEVL->getScalarType(),
- DebugLoc::getUnknown());
+ MaxEVL, Type::getInt32Ty(Plan.getContext()), DebugLoc::getUnknown());
Builder.setInsertPoint(Header, Header->getFirstNonPhi());
VPValue *PrevEVL = Builder.createScalarPhi(
@@ -536,9 +532,8 @@ void VPlanTransforms::addExplicitVectorLength(
Builder.setInsertPoint(CanonicalIVIncrement);
VPValue *OpVPEVL = VPEVL;
- auto *I32Ty = Type::getInt32Ty(Plan.getContext());
OpVPEVL = Builder.createScalarZExtOrTrunc(
- OpVPEVL, CanIVTy, I32Ty, CanonicalIVIncrement->getDebugLoc());
+ OpVPEVL, CanIVTy, CanonicalIVIncrement->getDebugLoc());
auto *NextIter = Builder.createAdd(
OpVPEVL, CurrentIteration, CanonicalIVIncrement->getDebugLoc(),
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index e51d8d7958f03..f545c63d691d9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -3192,9 +3192,8 @@ void VPVectorEndPointerRecipe::materializeOffset(unsigned Part) {
Type *IndexTy = DL.getIndexType(this->getScalarType());
VPValue *Stride =
Plan.getConstantInt(IndexTy, getStride(), /*IsSigned=*/true);
- Type *VFTy = VFVal->getScalarType();
- VPValue *VF = Builder.createScalarZExtOrTrunc(VFVal, IndexTy, VFTy,
- DebugLoc::getUnknown());
+ VPValue *VF =
+ Builder.createScalarZExtOrTrunc(VFVal, IndexTy, DebugLoc::getUnknown());
// Offset for Part0 = Offset0 = Stride * (VF - 1).
VPInstruction *VFMinusOne =
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 80d44ecd1a440..c336c653023cb 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -1018,8 +1018,8 @@ static VPValue *optimizeEarlyExitInductionUser(VPlan &Plan, VPValue *Op,
DebugLoc DL = ExtractR->getDebugLoc();
VPValue *FirstActiveLane = B.createFirstActiveLane(Mask, DL);
- FirstActiveLane = B.createScalarZExtOrTrunc(
- FirstActiveLane, CanonicalIVType, FirstActiveLane->getScalarType(), DL);
+ FirstActiveLane =
+ B.createScalarZExtOrTrunc(FirstActiveLane, CanonicalIVType, DL);
VPValue *EndValue = B.createAdd(CanonicalIV, FirstActiveLane, DL);
// `getOptimizableIVOf()` always returns the pre-incremented IV, so if it
@@ -3218,7 +3218,7 @@ expandVPWidenIntOrFpInduction(VPWidenIntOrFpInductionRecipe *WidenIVR) {
VF = Builder.createScalarCast(Instruction::CastOps::UIToFP, VF, StepTy,
DL);
else
- VF = Builder.createScalarZExtOrTrunc(VF, StepTy, VF->getScalarType(), DL);
+ VF = Builder.createScalarZExtOrTrunc(VF, StepTy, DL);
Inc = Builder.createNaryOp(MulOp, {Step, VF}, Flags);
Inc = Builder.createNaryOp(VPInstruction::Broadcast, Inc);
@@ -3288,7 +3288,7 @@ static void expandVPWidenPointerInduction(VPWidenPointerInductionRecipe *R) {
// Create the backedge value for the scalar pointer phi.
VPBasicBlock *ExitingBB = Plan->getVectorLoopRegion()->getExitingBasicBlock();
Builder.setInsertPoint(ExitingBB, ExitingBB->getTerminator()->getIterator());
- VF = Builder.createScalarZExtOrTrunc(VF, StepTy, VF->getScalarType(), DL);
+ VF = Builder.createScalarZExtOrTrunc(VF, StepTy, DL);
VPValue *Inc = Builder.createOverflowingOp(Instruction::Mul, {Step, VF});
VPValue *InductionGEP =
@@ -3303,10 +3303,9 @@ static void expandVPDerivedIV(VPDerivedIVRecipe *R) {
VPValue *Step = R->getStepValue();
VPValue *Index = R->getIndex();
Type *StepTy = Step->getScalarType();
- Type *IndexTy = Index->getScalarType();
Index = StepTy->isIntegerTy()
? Builder.createScalarSExtOrTrunc(
- Index, StepTy, IndexTy, DebugLoc::getCompilerGenerated())
+ Index, StepTy, DebugLoc::getCompilerGenerated())
: Builder.createScalarCast(Instruction::SIToFP, Index, StepTy,
DebugLoc::getCompilerGenerated());
switch (R->getInductionKind()) {
@@ -3851,11 +3850,10 @@ static bool handleUncountableExitsWithSideEffects(
VPBuilder MaskBuilder(HeaderVPBB, InsertIt);
VPValue *FirstActive = MaskBuilder.createFirstActiveLane(*Cond);
Type *IVScalarTy = IV->getScalarType();
- Type *FirstActiveTy = FirstActive->getScalarType();
VPValue *ALMMultiplier = Plan.getConstantInt(IVScalarTy, 1);
VPValue *Zero = Plan.getZero(IVScalarTy);
- FirstActive = MaskBuilder.createScalarZExtOrTrunc(FirstActive, IVScalarTy,
- FirstActiveTy, DebugLoc());
+ FirstActive =
+ MaskBuilder.createScalarZExtOrTrunc(FirstActive, IVScalarTy, DebugLoc());
VPValue *Mask = MaskBuilder.createNaryOp(VPInstruction::ActiveLaneMask,
{Zero, FirstActive, ALMMultiplier},
DebugLoc(), "uncountable.exit.mask");
@@ -4921,7 +4919,7 @@ VPlanTransforms::materializeAliasMask(VPlan &Plan, VPBasicBlock *AliasCheckVPBB,
VPInstruction::NumActiveLanes, {AliasMask}, nullptr, {}, {},
DebugLoc::getUnknown(), "num.active.lanes", IndexTy);
VPValue *ClampedVF = Builder.createScalarZExtOrTrunc(
- NumActive, IVTy, IndexTy, DebugLoc::getCompilerGenerated());
+ NumActive, IVTy, DebugLoc::getCompilerGenerated());
IncomingAliasMask->replaceAllUsesWith(AliasMask);
@@ -6941,7 +6939,7 @@ void VPlanTransforms::convertToStridedAccesses(VPlan &Plan,
VPBuilder Builder(Plan.getVectorPreheader());
I32VF = Builder.createScalarZExtOrTrunc(
&Plan.getVF(), Type::getInt32Ty(Plan.getContext()),
- Plan.getVF().getScalarType(), DebugLoc::getUnknown());
+ DebugLoc::getUnknown());
}
VPBuilder Builder(LoadR);
@@ -6958,8 +6956,7 @@ void VPlanTransforms::convertToStridedAccesses(VPlan &Plan,
assert(IndexTy == StrideInBytes->getScalarType() &&
"Stride type from SCEV must match the index type");
VPValue *CanIV = Builder.createScalarSExtOrTrunc(
- VectorLoop->getCanonicalIV(), IndexTy,
- VectorLoop->getCanonicalIVType(), DebugLoc::getUnknown());
+ VectorLoop->getCanonicalIV(), IndexTy, DebugLoc::getUnknown());
auto *AddRecPtr = cast<SCEVAddRecExpr>(PtrSCEV);
auto *Offset = Builder.createOverflowingOp(
Instruction::Mul, {CanIV, StrideInBytes},
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp b/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
index 09acc1a605341..a430de94cca14 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp
@@ -137,8 +137,8 @@ static void addStartIndexForScalarSteps(VPScalarIVStepsRecipe *Steps,
Instruction::Mul,
{StartIndex, Plan.getConstantInt(StartIndex->getScalarType(), Part)});
}
- StartIndex = Builder.createScalarSExtOrTrunc(
- StartIndex, IntStepTy, StartIndex->getScalarType(), Steps->getDebugLoc());
+ StartIndex = Builder.createScalarSExtOrTrunc(StartIndex, IntStepTy,
+ Steps->getDebugLoc());
if (BaseIVTy->isFloatingPointTy())
StartIndex = Builder.createScalarCast(Instruction::SIToFP, StartIndex,
@@ -339,9 +339,8 @@ void UnrollState::unrollRecipeByUF(VPRecipeBase &R) {
isa<VPWidenCanonicalIVRecipe>(R)
? Plan.getVectorLoopRegion()->getCanonicalIVType()
: DL.getIndexType(R.getVPSingleValue()->getScalarType());
- Type *VFTy = Plan.getVF().getScalarType();
- VPValue *VF = Builder.createScalarZExtOrTrunc(
- &Plan.getVF(), IndexTy, VFTy, DebugLoc::getUnknown());
+ VPValue *VF = Builder.createScalarZExtOrTrunc(&Plan.getVF(), IndexTy,
+ DebugLoc::getUnknown());
// VFxUF does not wrap, so VF * Part also cannot wrap.
VPValue *VFxPart = Builder.createOverflowingOp(
Instruction::Mul, {VF, Plan.getConstantInt(IndexTy, Part)},
More information about the llvm-commits
mailing list