Skip to content

Commit ff5b9a7

Browse files
[SVE] Remove calls to VectorType::getNumElements from CodeGen
Reviewers: efriedma, fpetrogalli, sdesmalen, RKSimon, arsenm Reviewed By: RKSimon Subscribers: wdng, tschuett, hiraditya, rkruppe, psnobl, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D82210
1 parent 469da66 commit ff5b9a7

10 files changed

+38
-27
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5329,7 +5329,7 @@ bool CodeGenPrepare::optimizeGatherScatterInst(Instruction *MemoryInst,
53295329
if (!RewriteGEP && Ops.size() == 2)
53305330
return false;
53315331

5332-
unsigned NumElts = cast<VectorType>(Ptr->getType())->getNumElements();
5332+
unsigned NumElts = cast<FixedVectorType>(Ptr->getType())->getNumElements();
53335333

53345334
IRBuilder<> Builder(MemoryInst);
53355335

@@ -6628,7 +6628,7 @@ bool CodeGenPrepare::optimizeShuffleVectorInst(ShuffleVectorInst *SVI) {
66286628
if (!NewType)
66296629
return false;
66306630

6631-
VectorType *SVIVecType = cast<VectorType>(SVI->getType());
6631+
auto *SVIVecType = cast<FixedVectorType>(SVI->getType());
66326632
assert(!NewType->isVectorTy() && "Expected a scalar type!");
66336633
assert(NewType->getScalarSizeInBits() == SVIVecType->getScalarSizeInBits() &&
66346634
"Expected a type of the same size!");

llvm/lib/CodeGen/ExpandReductions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ bool expandReductions(Function &F, const TargetTransformInfo *TTI) {
125125
if (!FMF.allowReassoc())
126126
Rdx = getOrderedReduction(Builder, Acc, Vec, getOpcode(ID), MRK);
127127
else {
128-
if (!isPowerOf2_32(cast<VectorType>(Vec->getType())->getNumElements()))
128+
if (!isPowerOf2_32(
129+
cast<FixedVectorType>(Vec->getType())->getNumElements()))
129130
continue;
130131

131132
Rdx = getShuffleReduction(Builder, Vec, getOpcode(ID), MRK);
@@ -146,7 +147,8 @@ bool expandReductions(Function &F, const TargetTransformInfo *TTI) {
146147
case Intrinsic::experimental_vector_reduce_fmax:
147148
case Intrinsic::experimental_vector_reduce_fmin: {
148149
Value *Vec = II->getArgOperand(0);
149-
if (!isPowerOf2_32(cast<VectorType>(Vec->getType())->getNumElements()))
150+
if (!isPowerOf2_32(
151+
cast<FixedVectorType>(Vec->getType())->getNumElements()))
150152
continue;
151153

152154
Rdx = getShuffleReduction(Builder, Vec, getOpcode(ID), MRK);

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ bool IRTranslator::translateGetElementPtr(const User &U,
10591059
// splat vector.
10601060
unsigned VectorWidth = 0;
10611061
if (auto *VT = dyn_cast<VectorType>(U.getType()))
1062-
VectorWidth = VT->getNumElements();
1062+
VectorWidth = cast<FixedVectorType>(VT)->getNumElements();
10631063

10641064
// We might need to splat the base pointer into a vector if the offsets
10651065
// are vectors.
@@ -1946,7 +1946,7 @@ bool IRTranslator::translateInsertElement(const User &U,
19461946
MachineIRBuilder &MIRBuilder) {
19471947
// If it is a <1 x Ty> vector, use the scalar as it is
19481948
// not a legal vector type in LLT.
1949-
if (cast<VectorType>(U.getType())->getNumElements() == 1)
1949+
if (cast<FixedVectorType>(U.getType())->getNumElements() == 1)
19501950
return translateCopy(U, *U.getOperand(1), MIRBuilder);
19511951

19521952
Register Res = getOrCreateVReg(U);
@@ -1961,7 +1961,7 @@ bool IRTranslator::translateExtractElement(const User &U,
19611961
MachineIRBuilder &MIRBuilder) {
19621962
// If it is a <1 x Ty> vector, use the scalar as it is
19631963
// not a legal vector type in LLT.
1964-
if (cast<VectorType>(U.getOperand(0)->getType())->getNumElements() == 1)
1964+
if (cast<FixedVectorType>(U.getOperand(0)->getType())->getNumElements() == 1)
19651965
return translateCopy(U, *U.getOperand(0), MIRBuilder);
19661966

19671967
Register Res = getOrCreateVReg(U);

llvm/lib/CodeGen/InterleavedAccessPass.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static bool isReInterleaveMask(ArrayRef<int> Mask, unsigned &Factor,
280280

281281
bool InterleavedAccess::lowerInterleavedLoad(
282282
LoadInst *LI, SmallVector<Instruction *, 32> &DeadInsts) {
283-
if (!LI->isSimple())
283+
if (!LI->isSimple() || isa<ScalableVectorType>(LI->getType()))
284284
return false;
285285

286286
SmallVector<ShuffleVectorInst *, 4> Shuffles;
@@ -308,7 +308,8 @@ bool InterleavedAccess::lowerInterleavedLoad(
308308

309309
unsigned Factor, Index;
310310

311-
unsigned NumLoadElements = cast<VectorType>(LI->getType())->getNumElements();
311+
unsigned NumLoadElements =
312+
cast<FixedVectorType>(LI->getType())->getNumElements();
312313
// Check if the first shufflevector is DE-interleave shuffle.
313314
if (!isDeInterleaveMask(Shuffles[0]->getShuffleMask(), Factor, Index,
314315
MaxFactor, NumLoadElements))
@@ -421,13 +422,13 @@ bool InterleavedAccess::lowerInterleavedStore(
421422
return false;
422423

423424
ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(SI->getValueOperand());
424-
if (!SVI || !SVI->hasOneUse())
425+
if (!SVI || !SVI->hasOneUse() || isa<ScalableVectorType>(SVI->getType()))
425426
return false;
426427

427428
// Check if the shufflevector is RE-interleave shuffle.
428429
unsigned Factor;
429430
unsigned OpNumElts =
430-
cast<VectorType>(SVI->getOperand(0)->getType())->getNumElements();
431+
cast<FixedVectorType>(SVI->getOperand(0)->getType())->getNumElements();
431432
if (!isReInterleaveMask(SVI->getShuffleMask(), Factor, MaxFactor, OpNumElts))
432433
return false;
433434

llvm/lib/CodeGen/InterleavedLoadCombinePass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,8 @@ bool InterleavedLoadCombineImpl::combine(std::list<VectorInfo> &InterleavedLoad,
12001200
IRBuilder<> Builder(InsertionPoint);
12011201
Type *ETy = InterleavedLoad.front().SVI->getType()->getElementType();
12021202
unsigned ElementsPerSVI =
1203-
InterleavedLoad.front().SVI->getType()->getNumElements();
1203+
cast<FixedVectorType>(InterleavedLoad.front().SVI->getType())
1204+
->getNumElements();
12041205
FixedVectorType *ILTy = FixedVectorType::get(ETy, Factor * ElementsPerSVI);
12051206

12061207
SmallVector<unsigned, 4> Indices;

llvm/lib/CodeGen/LowLevelType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using namespace llvm;
1919

2020
LLT llvm::getLLTForType(Type &Ty, const DataLayout &DL) {
2121
if (auto VTy = dyn_cast<VectorType>(&Ty)) {
22-
auto NumElements = VTy->getNumElements();
22+
auto NumElements = cast<FixedVectorType>(VTy)->getNumElements();
2323
LLT ScalarTy = getLLTForType(*VTy->getElementType(), DL);
2424
if (NumElements == 1)
2525
return ScalarTy;

llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static bool isConstantIntVector(Value *Mask) {
8383
if (!C)
8484
return false;
8585

86-
unsigned NumElts = cast<VectorType>(Mask->getType())->getNumElements();
86+
unsigned NumElts = cast<FixedVectorType>(Mask->getType())->getNumElements();
8787
for (unsigned i = 0; i != NumElts; ++i) {
8888
Constant *CElt = C->getAggregateElement(i);
8989
if (!CElt || !isa<ConstantInt>(CElt))
@@ -132,7 +132,7 @@ static void scalarizeMaskedLoad(CallInst *CI, bool &ModifiedDT) {
132132
Value *Src0 = CI->getArgOperand(3);
133133

134134
const Align AlignVal = cast<ConstantInt>(Alignment)->getAlignValue();
135-
VectorType *VecType = cast<VectorType>(CI->getType());
135+
VectorType *VecType = cast<FixedVectorType>(CI->getType());
136136

137137
Type *EltTy = VecType->getElementType();
138138

@@ -158,7 +158,7 @@ static void scalarizeMaskedLoad(CallInst *CI, bool &ModifiedDT) {
158158
Type *NewPtrType =
159159
EltTy->getPointerTo(Ptr->getType()->getPointerAddressSpace());
160160
Value *FirstEltPtr = Builder.CreateBitCast(Ptr, NewPtrType);
161-
unsigned VectorWidth = VecType->getNumElements();
161+
unsigned VectorWidth = cast<FixedVectorType>(VecType)->getNumElements();
162162

163163
// The result vector
164164
Value *VResult = Src0;
@@ -271,7 +271,7 @@ static void scalarizeMaskedStore(CallInst *CI, bool &ModifiedDT) {
271271
Value *Mask = CI->getArgOperand(3);
272272

273273
const Align AlignVal = cast<ConstantInt>(Alignment)->getAlignValue();
274-
VectorType *VecType = cast<VectorType>(Src->getType());
274+
auto *VecType = cast<VectorType>(Src->getType());
275275

276276
Type *EltTy = VecType->getElementType();
277277

@@ -295,7 +295,7 @@ static void scalarizeMaskedStore(CallInst *CI, bool &ModifiedDT) {
295295
Type *NewPtrType =
296296
EltTy->getPointerTo(Ptr->getType()->getPointerAddressSpace());
297297
Value *FirstEltPtr = Builder.CreateBitCast(Ptr, NewPtrType);
298-
unsigned VectorWidth = VecType->getNumElements();
298+
unsigned VectorWidth = cast<FixedVectorType>(VecType)->getNumElements();
299299

300300
if (isConstantIntVector(Mask)) {
301301
for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) {
@@ -396,7 +396,7 @@ static void scalarizeMaskedGather(CallInst *CI, bool &ModifiedDT) {
396396
Value *Mask = CI->getArgOperand(2);
397397
Value *Src0 = CI->getArgOperand(3);
398398

399-
VectorType *VecType = cast<VectorType>(CI->getType());
399+
auto *VecType = cast<FixedVectorType>(CI->getType());
400400
Type *EltTy = VecType->getElementType();
401401

402402
IRBuilder<> Builder(CI->getContext());
@@ -520,8 +520,8 @@ static void scalarizeMaskedScatter(CallInst *CI, bool &ModifiedDT) {
520520
Value *Alignment = CI->getArgOperand(2);
521521
Value *Mask = CI->getArgOperand(3);
522522

523-
assert(isa<VectorType>(Src->getType()) &&
524-
"Unexpected data type in masked scatter intrinsic");
523+
auto *SrcFVTy = cast<FixedVectorType>(Src->getType());
524+
525525
assert(
526526
isa<VectorType>(Ptrs->getType()) &&
527527
isa<PointerType>(cast<VectorType>(Ptrs->getType())->getElementType()) &&
@@ -534,7 +534,7 @@ static void scalarizeMaskedScatter(CallInst *CI, bool &ModifiedDT) {
534534
Builder.SetCurrentDebugLocation(CI->getDebugLoc());
535535

536536
MaybeAlign AlignVal = cast<ConstantInt>(Alignment)->getMaybeAlignValue();
537-
unsigned VectorWidth = cast<VectorType>(Src->getType())->getNumElements();
537+
unsigned VectorWidth = SrcFVTy->getNumElements();
538538

539539
// Shorten the way if the mask is a vector of constants.
540540
if (isConstantIntVector(Mask)) {
@@ -605,7 +605,7 @@ static void scalarizeMaskedExpandLoad(CallInst *CI, bool &ModifiedDT) {
605605
Value *Mask = CI->getArgOperand(1);
606606
Value *PassThru = CI->getArgOperand(2);
607607

608-
VectorType *VecType = cast<VectorType>(CI->getType());
608+
auto *VecType = cast<FixedVectorType>(CI->getType());
609609

610610
Type *EltTy = VecType->getElementType();
611611

@@ -718,7 +718,7 @@ static void scalarizeMaskedCompressStore(CallInst *CI, bool &ModifiedDT) {
718718
Value *Ptr = CI->getArgOperand(1);
719719
Value *Mask = CI->getArgOperand(2);
720720

721-
VectorType *VecType = cast<VectorType>(Src->getType());
721+
auto *VecType = cast<FixedVectorType>(Src->getType());
722722

723723
IRBuilder<> Builder(CI->getContext());
724724
Instruction *InsertPt = CI;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4295,7 +4295,7 @@ static bool getUniformBase(const Value *Ptr, SDValue &Base, SDValue &Index,
42954295

42964296
Base = SDB->getValue(C);
42974297

4298-
unsigned NumElts = cast<VectorType>(Ptr->getType())->getNumElements();
4298+
unsigned NumElts = cast<FixedVectorType>(Ptr->getType())->getNumElements();
42994299
EVT VT = EVT::getVectorVT(*DAG.getContext(), TLI.getPointerTy(DL), NumElts);
43004300
Index = DAG.getConstant(0, SDB->getCurSDLoc(), VT);
43014301
IndexType = ISD::SIGNED_SCALED;

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ static std::string scalarConstantToHexString(const Constant *C) {
17651765
} else {
17661766
unsigned NumElements;
17671767
if (auto *VTy = dyn_cast<VectorType>(Ty))
1768-
NumElements = VTy->getNumElements();
1768+
NumElements = cast<FixedVectorType>(VTy)->getNumElements();
17691769
else
17701770
NumElements = Ty->getArrayNumElements();
17711771
std::string HexString;

llvm/lib/CodeGen/ValueTypes.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,14 @@ EVT EVT::getExtendedVectorElementType() const {
122122

123123
unsigned EVT::getExtendedVectorNumElements() const {
124124
assert(isExtended() && "Type is not extended!");
125-
return cast<VectorType>(LLVMTy)->getNumElements();
125+
ElementCount EC = cast<VectorType>(LLVMTy)->getElementCount();
126+
if (EC.Scalable) {
127+
WithColor::warning()
128+
<< "The code that requested the fixed number of elements has made the "
129+
"assumption that this vector is not scalable. This assumption was "
130+
"not correct, and this may lead to broken code\n";
131+
}
132+
return EC.Min;
126133
}
127134

128135
ElementCount EVT::getExtendedVectorElementCount() const {

0 commit comments

Comments
 (0)