Skip to content

Commit 5e63083

Browse files
[SVE] Remove calls to VectorType::getNumElements from Transforms/Vectorize
Reviewed By: spatel Differential Revision: https://reviews.llvm.org/D82056
1 parent a1bdf8f commit 5e63083

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,8 +1027,8 @@ bool Vectorizer::vectorizeStoreChain(
10271027
unsigned EltSzInBytes = Sz / 8;
10281028
unsigned SzInBytes = EltSzInBytes * ChainSize;
10291029

1030-
VectorType *VecTy;
1031-
VectorType *VecStoreTy = dyn_cast<VectorType>(StoreTy);
1030+
FixedVectorType *VecTy;
1031+
auto *VecStoreTy = dyn_cast<FixedVectorType>(StoreTy);
10321032
if (VecStoreTy)
10331033
VecTy = FixedVectorType::get(StoreTy->getScalarType(),
10341034
Chain.size() * VecStoreTy->getNumElements());
@@ -1180,7 +1180,7 @@ bool Vectorizer::vectorizeLoadChain(
11801180
unsigned EltSzInBytes = Sz / 8;
11811181
unsigned SzInBytes = EltSzInBytes * ChainSize;
11821182
VectorType *VecTy;
1183-
VectorType *VecLoadTy = dyn_cast<VectorType>(LoadTy);
1183+
auto *VecLoadTy = dyn_cast<FixedVectorType>(LoadTy);
11841184
if (VecLoadTy)
11851185
VecTy = FixedVectorType::get(LoadTy->getScalarType(),
11861186
Chain.size() * VecLoadTy->getNumElements());

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ void InnerLoopVectorizer::widenIntOrFpInduction(PHINode *IV, TruncInst *Trunc) {
20352035
Value *InnerLoopVectorizer::getStepVector(Value *Val, int StartIdx, Value *Step,
20362036
Instruction::BinaryOps BinOp) {
20372037
// Create and check the types.
2038-
auto *ValVTy = cast<VectorType>(Val->getType());
2038+
auto *ValVTy = cast<FixedVectorType>(Val->getType());
20392039
int VLen = ValVTy->getNumElements();
20402040

20412041
Type *STy = Val->getType()->getScalarType();
@@ -2799,19 +2799,18 @@ Value *InnerLoopVectorizer::getOrCreateVectorTripCount(Loop *L) {
27992799
Value *InnerLoopVectorizer::createBitOrPointerCast(Value *V, VectorType *DstVTy,
28002800
const DataLayout &DL) {
28012801
// Verify that V is a vector type with same number of elements as DstVTy.
2802-
assert(isa<FixedVectorType>(DstVTy) &&
2803-
"Vector type is assumed to be fixed width.");
2804-
unsigned VF = DstVTy->getNumElements();
2805-
VectorType *SrcVecTy = cast<VectorType>(V->getType());
2802+
auto *DstFVTy = cast<FixedVectorType>(DstVTy);
2803+
unsigned VF = DstFVTy->getNumElements();
2804+
auto *SrcVecTy = cast<FixedVectorType>(V->getType());
28062805
assert((VF == SrcVecTy->getNumElements()) && "Vector dimensions do not match");
28072806
Type *SrcElemTy = SrcVecTy->getElementType();
2808-
Type *DstElemTy = DstVTy->getElementType();
2807+
Type *DstElemTy = DstFVTy->getElementType();
28092808
assert((DL.getTypeSizeInBits(SrcElemTy) == DL.getTypeSizeInBits(DstElemTy)) &&
28102809
"Vector elements must have same size");
28112810

28122811
// Do a direct cast if element types are castable.
28132812
if (CastInst::isBitOrNoopPointerCastable(SrcElemTy, DstElemTy, DL)) {
2814-
return Builder.CreateBitOrPointerCast(V, DstVTy);
2813+
return Builder.CreateBitOrPointerCast(V, DstFVTy);
28152814
}
28162815
// V cannot be directly casted to desired vector type.
28172816
// May happen when V is a floating point vector but DstVTy is a vector of
@@ -2825,7 +2824,7 @@ Value *InnerLoopVectorizer::createBitOrPointerCast(Value *V, VectorType *DstVTy,
28252824
IntegerType::getIntNTy(V->getContext(), DL.getTypeSizeInBits(SrcElemTy));
28262825
auto *VecIntTy = FixedVectorType::get(IntTy, VF);
28272826
Value *CastVal = Builder.CreateBitOrPointerCast(V, VecIntTy);
2828-
return Builder.CreateBitOrPointerCast(CastVal, DstVTy);
2827+
return Builder.CreateBitOrPointerCast(CastVal, DstFVTy);
28292828
}
28302829

28312830
void InnerLoopVectorizer::emitMinimumIterationCountCheck(Loop *L,
@@ -3526,7 +3525,8 @@ void InnerLoopVectorizer::truncateToMinimalBitwidths() {
35263525
Type *ScalarTruncatedTy =
35273526
IntegerType::get(OriginalTy->getContext(), KV.second);
35283527
auto *TruncatedTy = FixedVectorType::get(
3529-
ScalarTruncatedTy, cast<VectorType>(OriginalTy)->getNumElements());
3528+
ScalarTruncatedTy,
3529+
cast<FixedVectorType>(OriginalTy)->getNumElements());
35303530
if (TruncatedTy == OriginalTy)
35313531
continue;
35323532

@@ -3576,13 +3576,13 @@ void InnerLoopVectorizer::truncateToMinimalBitwidths() {
35763576
break;
35773577
}
35783578
} else if (auto *SI = dyn_cast<ShuffleVectorInst>(I)) {
3579-
auto Elements0 =
3580-
cast<VectorType>(SI->getOperand(0)->getType())->getNumElements();
3579+
auto Elements0 = cast<FixedVectorType>(SI->getOperand(0)->getType())
3580+
->getNumElements();
35813581
auto *O0 = B.CreateZExtOrTrunc(
35823582
SI->getOperand(0),
35833583
FixedVectorType::get(ScalarTruncatedTy, Elements0));
3584-
auto Elements1 =
3585-
cast<VectorType>(SI->getOperand(1)->getType())->getNumElements();
3584+
auto Elements1 = cast<FixedVectorType>(SI->getOperand(1)->getType())
3585+
->getNumElements();
35863586
auto *O1 = B.CreateZExtOrTrunc(
35873587
SI->getOperand(1),
35883588
FixedVectorType::get(ScalarTruncatedTy, Elements1));
@@ -3592,16 +3592,16 @@ void InnerLoopVectorizer::truncateToMinimalBitwidths() {
35923592
// Don't do anything with the operands, just extend the result.
35933593
continue;
35943594
} else if (auto *IE = dyn_cast<InsertElementInst>(I)) {
3595-
auto Elements =
3596-
cast<VectorType>(IE->getOperand(0)->getType())->getNumElements();
3595+
auto Elements = cast<FixedVectorType>(IE->getOperand(0)->getType())
3596+
->getNumElements();
35973597
auto *O0 = B.CreateZExtOrTrunc(
35983598
IE->getOperand(0),
35993599
FixedVectorType::get(ScalarTruncatedTy, Elements));
36003600
auto *O1 = B.CreateZExtOrTrunc(IE->getOperand(1), ScalarTruncatedTy);
36013601
NewI = B.CreateInsertElement(O0, O1, IE->getOperand(2));
36023602
} else if (auto *EE = dyn_cast<ExtractElementInst>(I)) {
3603-
auto Elements =
3604-
cast<VectorType>(EE->getOperand(0)->getType())->getNumElements();
3603+
auto Elements = cast<FixedVectorType>(EE->getOperand(0)->getType())
3604+
->getNumElements();
36053605
auto *O0 = B.CreateZExtOrTrunc(
36063606
EE->getOperand(0),
36073607
FixedVectorType::get(ScalarTruncatedTy, Elements));

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ static bool isCommutative(Instruction *I) {
286286
static Optional<TargetTransformInfo::ShuffleKind>
287287
isShuffle(ArrayRef<Value *> VL) {
288288
auto *EI0 = cast<ExtractElementInst>(VL[0]);
289-
unsigned Size = EI0->getVectorOperandType()->getNumElements();
289+
unsigned Size =
290+
cast<FixedVectorType>(EI0->getVectorOperandType())->getNumElements();
290291
Value *Vec1 = nullptr;
291292
Value *Vec2 = nullptr;
292293
enum ShuffleMode { Unknown, Select, Permute };
@@ -295,7 +296,7 @@ isShuffle(ArrayRef<Value *> VL) {
295296
auto *EI = cast<ExtractElementInst>(VL[I]);
296297
auto *Vec = EI->getVectorOperand();
297298
// All vector operands must have the same number of vector elements.
298-
if (cast<VectorType>(Vec->getType())->getNumElements() != Size)
299+
if (cast<FixedVectorType>(Vec->getType())->getNumElements() != Size)
299300
return None;
300301
auto *Idx = dyn_cast<ConstantInt>(EI->getIndexOperand());
301302
if (!Idx)
@@ -1411,7 +1412,7 @@ class BoUpSLP {
14111412

14121413
/// \returns the scalarization cost for this type. Scalarization in this
14131414
/// context means the creation of vectors from a group of scalars.
1414-
int getGatherCost(VectorType *Ty,
1415+
int getGatherCost(FixedVectorType *Ty,
14151416
const DenseSet<unsigned> &ShuffledIndices) const;
14161417

14171418
/// \returns the scalarization cost for this list of values. Assuming that
@@ -1424,7 +1425,7 @@ class BoUpSLP {
14241425
void setInsertPointAfterBundle(TreeEntry *E);
14251426

14261427
/// \returns a vector from a collection of scalars in \p VL.
1427-
Value *Gather(ArrayRef<Value *> VL, VectorType *Ty);
1428+
Value *Gather(ArrayRef<Value *> VL, FixedVectorType *Ty);
14281429

14291430
/// \returns whether the VectorizableTree is fully vectorizable and will
14301431
/// be beneficial even the tree height is tiny.
@@ -3166,7 +3167,7 @@ unsigned BoUpSLP::canMapToVector(Type *T, const DataLayout &DL) const {
31663167
N *= AT->getNumElements();
31673168
EltTy = AT->getElementType();
31683169
} else {
3169-
auto *VT = cast<VectorType>(EltTy);
3170+
auto *VT = cast<FixedVectorType>(EltTy);
31703171
N *= VT->getNumElements();
31713172
EltTy = VT->getElementType();
31723173
}
@@ -3204,7 +3205,7 @@ bool BoUpSLP::canReuseExtract(ArrayRef<Value *> VL, Value *OpValue,
32043205
if (!LI || !LI->isSimple() || !LI->hasNUses(VL.size()))
32053206
return false;
32063207
} else {
3207-
NElts = cast<VectorType>(Vec->getType())->getNumElements();
3208+
NElts = cast<FixedVectorType>(Vec->getType())->getNumElements();
32083209
}
32093210

32103211
if (NElts != VL.size())
@@ -3255,8 +3256,8 @@ bool BoUpSLP::areAllUsersVectorized(Instruction *I) const {
32553256
}
32563257

32573258
static std::pair<unsigned, unsigned>
3258-
getVectorCallCosts(CallInst *CI, VectorType *VecTy, TargetTransformInfo *TTI,
3259-
TargetLibraryInfo *TLI) {
3259+
getVectorCallCosts(CallInst *CI, FixedVectorType *VecTy,
3260+
TargetTransformInfo *TTI, TargetLibraryInfo *TLI) {
32603261
Intrinsic::ID ID = getVectorIntrinsicIDForCall(CI, TLI);
32613262

32623263
// Calculate the cost of the scalar and vector calls.
@@ -3928,7 +3929,7 @@ int BoUpSLP::getTreeCost() {
39283929
return Cost;
39293930
}
39303931

3931-
int BoUpSLP::getGatherCost(VectorType *Ty,
3932+
int BoUpSLP::getGatherCost(FixedVectorType *Ty,
39323933
const DenseSet<unsigned> &ShuffledIndices) const {
39333934
unsigned NumElts = Ty->getNumElements();
39343935
APInt DemandedElts = APInt::getNullValue(NumElts);
@@ -4041,7 +4042,7 @@ void BoUpSLP::setInsertPointAfterBundle(TreeEntry *E) {
40414042
Builder.SetCurrentDebugLocation(Front->getDebugLoc());
40424043
}
40434044

4044-
Value *BoUpSLP::Gather(ArrayRef<Value *> VL, VectorType *Ty) {
4045+
Value *BoUpSLP::Gather(ArrayRef<Value *> VL, FixedVectorType *Ty) {
40454046
Value *Vec = UndefValue::get(Ty);
40464047
// Generate the 'InsertElement' instruction.
40474048
for (unsigned i = 0; i < Ty->getNumElements(); ++i) {

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,10 @@ bool VectorCombine::foldBitcastShuf(Instruction &I) {
437437
TTI.getShuffleCost(TargetTransformInfo::SK_PermuteSingleSrc, SrcTy))
438438
return false;
439439

440-
unsigned DestNumElts = DestTy->getNumElements();
441-
unsigned SrcNumElts = SrcTy->getNumElements();
440+
// FIXME: it should be possible to implement the computation of the widened
441+
// shuffle mask in terms of ElementCount to work with scalable shuffles.
442+
unsigned DestNumElts = cast<FixedVectorType>(DestTy)->getNumElements();
443+
unsigned SrcNumElts = cast<FixedVectorType>(SrcTy)->getNumElements();
442444
SmallVector<int, 16> NewMask;
443445
if (SrcNumElts <= DestNumElts) {
444446
// The bitcast is from wide to narrow/equal elements. The shuffle mask can

0 commit comments

Comments
 (0)