Skip to content

Commit b96558f

Browse files
Clean up usages of asserting vector getters in Type
Summary: Remove usages of asserting vector getters in Type in preparation for the VectorType refactor. The existence of these functions complicates the refactor while adding little value. Reviewers: sunfish, sdesmalen, efriedma Reviewed By: efriedma Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77273
1 parent c6f13ce commit b96558f

File tree

8 files changed

+74
-61
lines changed

8 files changed

+74
-61
lines changed

llvm/include/llvm/Analysis/Utils/Local.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP,
6363

6464
// Splat the constant if needed.
6565
if (IntIdxTy->isVectorTy() && !OpC->getType()->isVectorTy())
66-
OpC = ConstantVector::getSplat(IntIdxTy->getVectorElementCount(), OpC);
66+
OpC = ConstantVector::getSplat(
67+
cast<VectorType>(IntIdxTy)->getElementCount(), OpC);
6768

6869
Constant *Scale = ConstantInt::get(IntIdxTy, Size);
6970
Constant *OC = ConstantExpr::getIntegerCast(OpC, IntIdxTy, true /*SExt*/);
@@ -76,7 +77,8 @@ Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP,
7677

7778
// Splat the index if needed.
7879
if (IntIdxTy->isVectorTy() && !Op->getType()->isVectorTy())
79-
Op = Builder->CreateVectorSplat(IntIdxTy->getVectorNumElements(), Op);
80+
Op = Builder->CreateVectorSplat(
81+
cast<VectorType>(IntIdxTy)->getNumElements(), Op);
8082

8183
// Convert to correct type.
8284
if (Op->getType() != IntIdxTy)

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
155155

156156
// If the element types match, IR can fold it.
157157
unsigned NumDstElt = DestVTy->getNumElements();
158-
unsigned NumSrcElt = C->getType()->getVectorNumElements();
158+
unsigned NumSrcElt = cast<VectorType>(C->getType())->getNumElements();
159159
if (NumDstElt == NumSrcElt)
160160
return ConstantExpr::getBitCast(C, DestTy);
161161

162-
Type *SrcEltTy = C->getType()->getVectorElementType();
162+
Type *SrcEltTy = cast<VectorType>(C->getType())->getElementType();
163163
Type *DstEltTy = DestVTy->getElementType();
164164

165165
// Otherwise, we're changing the number of elements in a vector, which
@@ -218,7 +218,8 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
218218
for (unsigned j = 0; j != Ratio; ++j) {
219219
Constant *Src = C->getAggregateElement(SrcElt++);
220220
if (Src && isa<UndefValue>(Src))
221-
Src = Constant::getNullValue(C->getType()->getVectorElementType());
221+
Src = Constant::getNullValue(
222+
cast<VectorType>(C->getType())->getElementType());
222223
else
223224
Src = dyn_cast_or_null<ConstantInt>(Src);
224225
if (!Src) // Reject constantexpr elements.
@@ -469,8 +470,8 @@ bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset, unsigned char *CurPtr,
469470
NumElts = AT->getNumElements();
470471
EltTy = AT->getElementType();
471472
} else {
472-
NumElts = C->getType()->getVectorNumElements();
473-
EltTy = C->getType()->getVectorElementType();
473+
NumElts = cast<VectorType>(C->getType())->getNumElements();
474+
EltTy = cast<VectorType>(C->getType())->getElementType();
474475
}
475476
uint64_t EltSize = DL.getTypeAllocSize(EltTy);
476477
uint64_t Index = ByteOffset / EltSize;
@@ -508,7 +509,7 @@ bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset, unsigned char *CurPtr,
508509
Constant *FoldReinterpretLoadFromConstPtr(Constant *C, Type *LoadTy,
509510
const DataLayout &DL) {
510511
// Bail out early. Not expect to load from scalable global variable.
511-
if (LoadTy->isVectorTy() && LoadTy->getVectorIsScalable())
512+
if (LoadTy->isVectorTy() && cast<VectorType>(LoadTy)->isScalable())
512513
return nullptr;
513514

514515
auto *PTy = cast<PointerType>(C->getType());
@@ -836,7 +837,7 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP,
836837
Type *ResElemTy = GEP->getResultElementType();
837838
Type *ResTy = GEP->getType();
838839
if (!SrcElemTy->isSized() ||
839-
(SrcElemTy->isVectorTy() && SrcElemTy->getVectorIsScalable()))
840+
(SrcElemTy->isVectorTy() && cast<VectorType>(SrcElemTy)->isScalable()))
840841
return nullptr;
841842

842843
if (Constant *C = CastGEPIndices(SrcElemTy, Ops, ResTy,
@@ -2571,7 +2572,7 @@ static Constant *ConstantFoldVectorCall(StringRef Name,
25712572

25722573
// Do not iterate on scalable vector. The number of elements is unknown at
25732574
// compile-time.
2574-
if (VTy->getVectorIsScalable())
2575+
if (VTy->isScalable())
25752576
return nullptr;
25762577

25772578
if (IntrinsicID == Intrinsic::masked_load) {

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -945,8 +945,9 @@ static Value *simplifyDivRem(Value *Op0, Value *Op1, bool IsDiv) {
945945
// If any element of a constant divisor vector is zero or undef, the whole op
946946
// is undef.
947947
auto *Op1C = dyn_cast<Constant>(Op1);
948-
if (Op1C && Ty->isVectorTy()) {
949-
unsigned NumElts = Ty->getVectorNumElements();
948+
auto *VTy = dyn_cast<VectorType>(Ty);
949+
if (Op1C && VTy) {
950+
unsigned NumElts = VTy->getNumElements();
950951
for (unsigned i = 0; i != NumElts; ++i) {
951952
Constant *Elt = Op1C->getAggregateElement(i);
952953
if (Elt && (Elt->isNullValue() || isa<UndefValue>(Elt)))
@@ -1221,7 +1222,8 @@ static bool isUndefShift(Value *Amount) {
12211222

12221223
// If all lanes of a vector shift are undefined the whole shift is.
12231224
if (isa<ConstantVector>(C) || isa<ConstantDataVector>(C)) {
1224-
for (unsigned I = 0, E = C->getType()->getVectorNumElements(); I != E; ++I)
1225+
for (unsigned I = 0, E = cast<VectorType>(C->getType())->getNumElements();
1226+
I != E; ++I)
12251227
if (!isUndefShift(C->getAggregateElement(I)))
12261228
return false;
12271229
return true;
@@ -4011,7 +4013,7 @@ static Value *SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
40114013
Constant *TrueC, *FalseC;
40124014
if (TrueVal->getType()->isVectorTy() && match(TrueVal, m_Constant(TrueC)) &&
40134015
match(FalseVal, m_Constant(FalseC))) {
4014-
unsigned NumElts = TrueC->getType()->getVectorNumElements();
4016+
unsigned NumElts = cast<VectorType>(TrueC->getType())->getNumElements();
40154017
SmallVector<Constant *, 16> NewC;
40164018
for (unsigned i = 0; i != NumElts; ++i) {
40174019
// Bail out on incomplete vector constants.
@@ -4081,7 +4083,7 @@ static Value *SimplifyGEPInst(Type *SrcTy, ArrayRef<Value *> Ops,
40814083
return UndefValue::get(GEPTy);
40824084

40834085
bool IsScalableVec =
4084-
SrcTy->isVectorTy() ? SrcTy->getVectorIsScalable() : false;
4086+
isa<VectorType>(SrcTy) && cast<VectorType>(SrcTy)->isScalable();
40854087

40864088
if (Ops.size() == 2) {
40874089
// getelementptr P, 0 -> P.
@@ -4223,8 +4225,8 @@ Value *llvm::SimplifyInsertElementInst(Value *Vec, Value *Val, Value *Idx,
42234225

42244226
// For fixed-length vector, fold into undef if index is out of bounds.
42254227
if (auto *CI = dyn_cast<ConstantInt>(Idx)) {
4226-
if (!Vec->getType()->getVectorIsScalable() &&
4227-
CI->uge(Vec->getType()->getVectorNumElements()))
4228+
if (!cast<VectorType>(Vec->getType())->isScalable() &&
4229+
CI->uge(cast<VectorType>(Vec->getType())->getNumElements()))
42284230
return UndefValue::get(Vec->getType());
42294231
}
42304232

@@ -4280,6 +4282,7 @@ Value *llvm::SimplifyExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs,
42804282
/// If not, this returns null.
42814283
static Value *SimplifyExtractElementInst(Value *Vec, Value *Idx, const SimplifyQuery &,
42824284
unsigned) {
4285+
auto *VecVTy = cast<VectorType>(Vec->getType());
42834286
if (auto *CVec = dyn_cast<Constant>(Vec)) {
42844287
if (auto *CIdx = dyn_cast<Constant>(Idx))
42854288
return ConstantFoldExtractElementInstruction(CVec, CIdx);
@@ -4289,24 +4292,23 @@ static Value *SimplifyExtractElementInst(Value *Vec, Value *Idx, const SimplifyQ
42894292
return Splat;
42904293

42914294
if (isa<UndefValue>(Vec))
4292-
return UndefValue::get(Vec->getType()->getVectorElementType());
4295+
return UndefValue::get(VecVTy->getElementType());
42934296
}
42944297

42954298
// If extracting a specified index from the vector, see if we can recursively
42964299
// find a previously computed scalar that was inserted into the vector.
42974300
if (auto *IdxC = dyn_cast<ConstantInt>(Idx)) {
42984301
// For fixed-length vector, fold into undef if index is out of bounds.
4299-
if (!Vec->getType()->getVectorIsScalable() &&
4300-
IdxC->getValue().uge(Vec->getType()->getVectorNumElements()))
4301-
return UndefValue::get(Vec->getType()->getVectorElementType());
4302+
if (!VecVTy->isScalable() && IdxC->getValue().uge(VecVTy->getNumElements()))
4303+
return UndefValue::get(VecVTy->getElementType());
43024304
if (Value *Elt = findScalarElement(Vec, IdxC->getZExtValue()))
43034305
return Elt;
43044306
}
43054307

43064308
// An undef extract index can be arbitrarily chosen to be an out-of-range
43074309
// index value, which would result in the instruction being undef.
43084310
if (isa<UndefValue>(Idx))
4309-
return UndefValue::get(Vec->getType()->getVectorElementType());
4311+
return UndefValue::get(VecVTy->getElementType());
43104312

43114313
return nullptr;
43124314
}
@@ -4403,7 +4405,7 @@ static Value *foldIdentityShuffles(int DestElt, Value *Op0, Value *Op1,
44034405
return nullptr;
44044406

44054407
// The mask value chooses which source operand we need to look at next.
4406-
int InVecNumElts = Op0->getType()->getVectorNumElements();
4408+
int InVecNumElts = cast<VectorType>(Op0->getType())->getNumElements();
44074409
int RootElt = MaskVal;
44084410
Value *SourceOp = Op0;
44094411
if (MaskVal >= InVecNumElts) {
@@ -4446,9 +4448,9 @@ static Value *SimplifyShuffleVectorInst(Value *Op0, Value *Op1,
44464448
if (all_of(Mask, [](int Elem) { return Elem == UndefMaskElem; }))
44474449
return UndefValue::get(RetTy);
44484450

4449-
Type *InVecTy = Op0->getType();
4451+
auto *InVecTy = cast<VectorType>(Op0->getType());
44504452
unsigned MaskNumElts = Mask.size();
4451-
ElementCount InVecEltCount = InVecTy->getVectorElementCount();
4453+
ElementCount InVecEltCount = InVecTy->getElementCount();
44524454

44534455
bool Scalable = InVecEltCount.Scalable;
44544456

llvm/lib/Analysis/Loads.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ bool llvm::isDereferenceableAndAlignedPointer(const Value *V, Type *Ty,
148148
const DominatorTree *DT) {
149149
// For unsized types or scalable vectors we don't know exactly how many bytes
150150
// are dereferenced, so bail out.
151-
if (!Ty->isSized() || (Ty->isVectorTy() && Ty->getVectorIsScalable()))
151+
if (!Ty->isSized() ||
152+
(Ty->isVectorTy() && cast<VectorType>(Ty)->isScalable()))
152153
return false;
153154

154155
// When dereferenceability information is provided by a dereferenceable

llvm/lib/Analysis/MemoryBuiltins.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ SizeOffsetType ObjectSizeOffsetVisitor::visitAllocaInst(AllocaInst &I) {
650650
return unknown();
651651

652652
if (I.getAllocatedType()->isVectorTy() &&
653-
I.getAllocatedType()->getVectorIsScalable())
653+
cast<VectorType>(I.getAllocatedType())->isScalable())
654654
return unknown();
655655

656656
APInt Size(IntTyBits, DL.getTypeAllocSize(I.getAllocatedType()));

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ static bool matchPairwiseShuffleMask(ShuffleVectorInst *SI, bool IsLeft,
874874
else if (!SI)
875875
return false;
876876

877-
SmallVector<int, 32> Mask(SI->getType()->getVectorNumElements(), -1);
877+
SmallVector<int, 32> Mask(SI->getType()->getNumElements(), -1);
878878

879879
// Build a mask of 0, 2, ... (left) or 1, 3, ... (right) depending on whether
880880
// we look at the left or right side.
@@ -1036,8 +1036,8 @@ static ReductionKind matchPairwiseReduction(const ExtractElementInst *ReduxRoot,
10361036
if (!RD)
10371037
return RK_None;
10381038

1039-
Type *VecTy = RdxStart->getType();
1040-
unsigned NumVecElems = VecTy->getVectorNumElements();
1039+
auto *VecTy = cast<VectorType>(RdxStart->getType());
1040+
unsigned NumVecElems = VecTy->getNumElements();
10411041
if (!isPowerOf2_32(NumVecElems))
10421042
return RK_None;
10431043

@@ -1101,8 +1101,8 @@ matchVectorSplittingReduction(const ExtractElementInst *ReduxRoot,
11011101
if (!RD)
11021102
return RK_None;
11031103

1104-
Type *VecTy = ReduxRoot->getOperand(0)->getType();
1105-
unsigned NumVecElems = VecTy->getVectorNumElements();
1104+
auto *VecTy = cast<VectorType>(ReduxRoot->getOperand(0)->getType());
1105+
unsigned NumVecElems = VecTy->getNumElements();
11061106
if (!isPowerOf2_32(NumVecElems))
11071107
return RK_None;
11081108

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,12 @@ static bool getShuffleDemandedElts(const ShuffleVectorInst *Shuf,
168168
APInt &DemandedLHS, APInt &DemandedRHS) {
169169
// The length of scalable vectors is unknown at compile time, thus we
170170
// cannot check their values
171-
if (Shuf->getType()->getVectorElementCount().Scalable)
171+
if (Shuf->getType()->isScalable())
172172
return false;
173173

174-
int NumElts = Shuf->getOperand(0)->getType()->getVectorNumElements();
175-
int NumMaskElts = Shuf->getType()->getVectorNumElements();
174+
int NumElts =
175+
cast<VectorType>(Shuf->getOperand(0)->getType())->getNumElements();
176+
int NumMaskElts = Shuf->getType()->getNumElements();
176177
DemandedLHS = DemandedRHS = APInt::getNullValue(NumElts);
177178
if (DemandedElts.isNullValue())
178179
return true;
@@ -206,9 +207,10 @@ static void computeKnownBits(const Value *V, const APInt &DemandedElts,
206207
static void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
207208
const Query &Q) {
208209
Type *Ty = V->getType();
209-
APInt DemandedElts = Ty->isVectorTy()
210-
? APInt::getAllOnesValue(Ty->getVectorNumElements())
211-
: APInt(1, 1);
210+
APInt DemandedElts =
211+
Ty->isVectorTy()
212+
? APInt::getAllOnesValue(cast<VectorType>(Ty)->getNumElements())
213+
: APInt(1, 1);
212214
computeKnownBits(V, DemandedElts, Known, Depth, Q);
213215
}
214216

@@ -373,9 +375,10 @@ static unsigned ComputeNumSignBits(const Value *V, const APInt &DemandedElts,
373375
static unsigned ComputeNumSignBits(const Value *V, unsigned Depth,
374376
const Query &Q) {
375377
Type *Ty = V->getType();
376-
APInt DemandedElts = Ty->isVectorTy()
377-
? APInt::getAllOnesValue(Ty->getVectorNumElements())
378-
: APInt(1, 1);
378+
APInt DemandedElts =
379+
Ty->isVectorTy()
380+
? APInt::getAllOnesValue(cast<VectorType>(Ty)->getNumElements())
381+
: APInt(1, 1);
379382
return ComputeNumSignBits(V, DemandedElts, Depth, Q);
380383
}
381384

@@ -1791,7 +1794,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
17911794
const Value *Vec = I->getOperand(0);
17921795
const Value *Idx = I->getOperand(1);
17931796
auto *CIdx = dyn_cast<ConstantInt>(Idx);
1794-
unsigned NumElts = Vec->getType()->getVectorNumElements();
1797+
unsigned NumElts = cast<VectorType>(Vec->getType())->getNumElements();
17951798
APInt DemandedVecElts = APInt::getAllOnesValue(NumElts);
17961799
if (CIdx && CIdx->getValue().ult(NumElts))
17971800
DemandedVecElts = APInt::getOneBitSet(NumElts, CIdx->getZExtValue());
@@ -1870,8 +1873,8 @@ void computeKnownBits(const Value *V, const APInt &DemandedElts,
18701873
Type *Ty = V->getType();
18711874
assert((Ty->isIntOrIntVectorTy(BitWidth) || Ty->isPtrOrPtrVectorTy()) &&
18721875
"Not integer or pointer type!");
1873-
assert(((Ty->isVectorTy() &&
1874-
Ty->getVectorNumElements() == DemandedElts.getBitWidth()) ||
1876+
assert(((Ty->isVectorTy() && cast<VectorType>(Ty)->getNumElements() ==
1877+
DemandedElts.getBitWidth()) ||
18751878
(!Ty->isVectorTy() && DemandedElts == APInt(1, 1))) &&
18761879
"Unexpected vector size");
18771880

@@ -2510,7 +2513,7 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
25102513
const Value *Vec = EEI->getVectorOperand();
25112514
const Value *Idx = EEI->getIndexOperand();
25122515
auto *CIdx = dyn_cast<ConstantInt>(Idx);
2513-
unsigned NumElts = Vec->getType()->getVectorNumElements();
2516+
unsigned NumElts = cast<VectorType>(Vec->getType())->getNumElements();
25142517
APInt DemandedVecElts = APInt::getAllOnesValue(NumElts);
25152518
if (CIdx && CIdx->getValue().ult(NumElts))
25162519
DemandedVecElts = APInt::getOneBitSet(NumElts, CIdx->getZExtValue());
@@ -2524,9 +2527,10 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
25242527

25252528
bool isKnownNonZero(const Value* V, unsigned Depth, const Query& Q) {
25262529
Type *Ty = V->getType();
2527-
APInt DemandedElts = Ty->isVectorTy()
2528-
? APInt::getAllOnesValue(Ty->getVectorNumElements())
2529-
: APInt(1, 1);
2530+
APInt DemandedElts =
2531+
Ty->isVectorTy()
2532+
? APInt::getAllOnesValue(cast<VectorType>(Ty)->getNumElements())
2533+
: APInt(1, 1);
25302534
return isKnownNonZero(V, DemandedElts, Depth, Q);
25312535
}
25322536

@@ -2627,7 +2631,7 @@ static unsigned computeNumSignBitsVectorConstant(const Value *V,
26272631
return 0;
26282632

26292633
unsigned MinSignBits = TyBits;
2630-
unsigned NumElts = CV->getType()->getVectorNumElements();
2634+
unsigned NumElts = cast<VectorType>(CV->getType())->getNumElements();
26312635
for (unsigned i = 0; i != NumElts; ++i) {
26322636
if (!DemandedElts[i])
26332637
continue;
@@ -2670,8 +2674,8 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
26702674
// same behavior for poison though -- that's a FIXME today.
26712675

26722676
Type *Ty = V->getType();
2673-
assert(((Ty->isVectorTy() &&
2674-
Ty->getVectorNumElements() == DemandedElts.getBitWidth()) ||
2677+
assert(((Ty->isVectorTy() && cast<VectorType>(Ty)->getNumElements() ==
2678+
DemandedElts.getBitWidth()) ||
26752679
(!Ty->isVectorTy() && DemandedElts == APInt(1, 1))) &&
26762680
"Unexpected vector size");
26772681

@@ -3246,8 +3250,8 @@ static bool cannotBeOrderedLessThanZeroImpl(const Value *V,
32463250

32473251
// Handle vector of constants.
32483252
if (auto *CV = dyn_cast<Constant>(V)) {
3249-
if (CV->getType()->isVectorTy()) {
3250-
unsigned NumElts = CV->getType()->getVectorNumElements();
3253+
if (auto *CVVTy = dyn_cast<VectorType>(CV->getType())) {
3254+
unsigned NumElts = CVVTy->getNumElements();
32513255
for (unsigned i = 0; i != NumElts; ++i) {
32523256
auto *CFP = dyn_cast_or_null<ConstantFP>(CV->getAggregateElement(i));
32533257
if (!CFP)
@@ -3423,7 +3427,7 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
34233427
return false;
34243428

34253429
// For vectors, verify that each element is not infinity.
3426-
unsigned NumElts = V->getType()->getVectorNumElements();
3430+
unsigned NumElts = cast<VectorType>(V->getType())->getNumElements();
34273431
for (unsigned i = 0; i != NumElts; ++i) {
34283432
Constant *Elt = cast<Constant>(V)->getAggregateElement(i);
34293433
if (!Elt)
@@ -3524,7 +3528,7 @@ bool llvm::isKnownNeverNaN(const Value *V, const TargetLibraryInfo *TLI,
35243528
return false;
35253529

35263530
// For vectors, verify that each element is not NaN.
3527-
unsigned NumElts = V->getType()->getVectorNumElements();
3531+
unsigned NumElts = cast<VectorType>(V->getType())->getNumElements();
35283532
for (unsigned i = 0; i != NumElts; ++i) {
35293533
Constant *Elt = cast<Constant>(V)->getAggregateElement(i);
35303534
if (!Elt)

0 commit comments

Comments
 (0)