Skip to content

Commit 3297e9b

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: rriddle, sdesmalen, efriedma Reviewed By: efriedma Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77259
1 parent 05192e5 commit 3297e9b

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,8 +1913,8 @@ void InnerLoopVectorizer::widenIntOrFpInduction(PHINode *IV, TruncInst *Trunc) {
19131913
Value *InnerLoopVectorizer::getStepVector(Value *Val, int StartIdx, Value *Step,
19141914
Instruction::BinaryOps BinOp) {
19151915
// Create and check the types.
1916-
assert(Val->getType()->isVectorTy() && "Must be a vector");
1917-
int VLen = Val->getType()->getVectorNumElements();
1916+
auto *ValVTy = cast<VectorType>(Val->getType());
1917+
int VLen = ValVTy->getNumElements();
19181918

19191919
Type *STy = Val->getType()->getScalarType();
19201920
assert((STy->isIntegerTy() || STy->isFloatingPointTy()) &&
@@ -3318,13 +3318,14 @@ unsigned LoopVectorizationCostModel::getVectorIntrinsicCost(CallInst *CI,
33183318
}
33193319

33203320
static Type *smallestIntegerVectorType(Type *T1, Type *T2) {
3321-
auto *I1 = cast<IntegerType>(T1->getVectorElementType());
3322-
auto *I2 = cast<IntegerType>(T2->getVectorElementType());
3321+
auto *I1 = cast<IntegerType>(cast<VectorType>(T1)->getElementType());
3322+
auto *I2 = cast<IntegerType>(cast<VectorType>(T2)->getElementType());
33233323
return I1->getBitWidth() < I2->getBitWidth() ? T1 : T2;
33243324
}
3325+
33253326
static Type *largestIntegerVectorType(Type *T1, Type *T2) {
3326-
auto *I1 = cast<IntegerType>(T1->getVectorElementType());
3327-
auto *I2 = cast<IntegerType>(T2->getVectorElementType());
3327+
auto *I1 = cast<IntegerType>(cast<VectorType>(T1)->getElementType());
3328+
auto *I2 = cast<IntegerType>(cast<VectorType>(T2)->getElementType());
33283329
return I1->getBitWidth() > I2->getBitWidth() ? T1 : T2;
33293330
}
33303331

@@ -3347,8 +3348,8 @@ void InnerLoopVectorizer::truncateToMinimalBitwidths() {
33473348
Type *OriginalTy = I->getType();
33483349
Type *ScalarTruncatedTy =
33493350
IntegerType::get(OriginalTy->getContext(), KV.second);
3350-
Type *TruncatedTy = VectorType::get(ScalarTruncatedTy,
3351-
OriginalTy->getVectorNumElements());
3351+
Type *TruncatedTy = VectorType::get(
3352+
ScalarTruncatedTy, cast<VectorType>(OriginalTy)->getNumElements());
33523353
if (TruncatedTy == OriginalTy)
33533354
continue;
33543355

@@ -3398,10 +3399,12 @@ void InnerLoopVectorizer::truncateToMinimalBitwidths() {
33983399
break;
33993400
}
34003401
} else if (auto *SI = dyn_cast<ShuffleVectorInst>(I)) {
3401-
auto Elements0 = SI->getOperand(0)->getType()->getVectorNumElements();
3402+
auto Elements0 =
3403+
cast<VectorType>(SI->getOperand(0)->getType())->getNumElements();
34023404
auto *O0 = B.CreateZExtOrTrunc(
34033405
SI->getOperand(0), VectorType::get(ScalarTruncatedTy, Elements0));
3404-
auto Elements1 = SI->getOperand(1)->getType()->getVectorNumElements();
3406+
auto Elements1 =
3407+
cast<VectorType>(SI->getOperand(1)->getType())->getNumElements();
34053408
auto *O1 = B.CreateZExtOrTrunc(
34063409
SI->getOperand(1), VectorType::get(ScalarTruncatedTy, Elements1));
34073410

@@ -3410,13 +3413,15 @@ void InnerLoopVectorizer::truncateToMinimalBitwidths() {
34103413
// Don't do anything with the operands, just extend the result.
34113414
continue;
34123415
} else if (auto *IE = dyn_cast<InsertElementInst>(I)) {
3413-
auto Elements = IE->getOperand(0)->getType()->getVectorNumElements();
3416+
auto Elements =
3417+
cast<VectorType>(IE->getOperand(0)->getType())->getNumElements();
34143418
auto *O0 = B.CreateZExtOrTrunc(
34153419
IE->getOperand(0), VectorType::get(ScalarTruncatedTy, Elements));
34163420
auto *O1 = B.CreateZExtOrTrunc(IE->getOperand(1), ScalarTruncatedTy);
34173421
NewI = B.CreateInsertElement(O0, O1, IE->getOperand(2));
34183422
} else if (auto *EE = dyn_cast<ExtractElementInst>(I)) {
3419-
auto Elements = EE->getOperand(0)->getType()->getVectorNumElements();
3423+
auto Elements =
3424+
cast<VectorType>(EE->getOperand(0)->getType())->getNumElements();
34203425
auto *O0 = B.CreateZExtOrTrunc(
34213426
EE->getOperand(0), VectorType::get(ScalarTruncatedTy, Elements));
34223427
NewI = B.CreateExtractElement(O0, EE->getOperand(2));

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static bool isCommutative(Instruction *I) {
285285
static Optional<TargetTransformInfo::ShuffleKind>
286286
isShuffle(ArrayRef<Value *> VL) {
287287
auto *EI0 = cast<ExtractElementInst>(VL[0]);
288-
unsigned Size = EI0->getVectorOperandType()->getVectorNumElements();
288+
unsigned Size = EI0->getVectorOperandType()->getNumElements();
289289
Value *Vec1 = nullptr;
290290
Value *Vec2 = nullptr;
291291
enum ShuffleMode { Unknown, Select, Permute };
@@ -294,7 +294,7 @@ isShuffle(ArrayRef<Value *> VL) {
294294
auto *EI = cast<ExtractElementInst>(VL[I]);
295295
auto *Vec = EI->getVectorOperand();
296296
// All vector operands must have the same number of vector elements.
297-
if (Vec->getType()->getVectorNumElements() != Size)
297+
if (cast<VectorType>(Vec->getType())->getNumElements() != Size)
298298
return None;
299299
auto *Idx = dyn_cast<ConstantInt>(EI->getIndexOperand());
300300
if (!Idx)
@@ -3182,7 +3182,7 @@ bool BoUpSLP::canReuseExtract(ArrayRef<Value *> VL, Value *OpValue,
31823182
if (!LI || !LI->isSimple() || !LI->hasNUses(VL.size()))
31833183
return false;
31843184
} else {
3185-
NElts = Vec->getType()->getVectorNumElements();
3185+
NElts = cast<VectorType>(Vec->getType())->getNumElements();
31863186
}
31873187

31883188
if (NElts != VL.size())

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,10 @@ static bool foldExtractExtract(Instruction &I, const TargetTransformInfo &TTI) {
236236
// ShufMask = { 2, undef, undef, undef }
237237
uint64_t SplatIndex = ConvertToShuffle == Ext0 ? C0 : C1;
238238
uint64_t CheapExtIndex = ConvertToShuffle == Ext0 ? C1 : C0;
239-
Type *VecTy = V0->getType();
239+
auto *VecTy = cast<VectorType>(V0->getType());
240240
Type *I32Ty = IntegerType::getInt32Ty(I.getContext());
241241
UndefValue *Undef = UndefValue::get(I32Ty);
242-
SmallVector<Constant *, 32> ShufMask(VecTy->getVectorNumElements(), Undef);
242+
SmallVector<Constant *, 32> ShufMask(VecTy->getNumElements(), Undef);
243243
ShufMask[CheapExtIndex] = ConstantInt::get(I32Ty, SplatIndex);
244244
IRBuilder<> Builder(ConvertToShuffle);
245245

@@ -272,15 +272,14 @@ static bool foldBitcastShuf(Instruction &I, const TargetTransformInfo &TTI) {
272272
m_Mask(Mask))))))
273273
return false;
274274

275-
Type *DestTy = I.getType();
276-
Type *SrcTy = V->getType();
277-
if (!DestTy->isVectorTy() || I.getOperand(0)->getType() != SrcTy)
275+
auto *DestTy = dyn_cast<VectorType>(I.getType());
276+
auto *SrcTy = cast<VectorType>(V->getType());
277+
if (!DestTy || I.getOperand(0)->getType() != SrcTy)
278278
return false;
279279

280280
// TODO: Handle bitcast from narrow element type to wide element type.
281-
assert(SrcTy->isVectorTy() && "Shuffle of non-vector type?");
282-
unsigned DestNumElts = DestTy->getVectorNumElements();
283-
unsigned SrcNumElts = SrcTy->getVectorNumElements();
281+
unsigned DestNumElts = DestTy->getNumElements();
282+
unsigned SrcNumElts = SrcTy->getNumElements();
284283
if (SrcNumElts > DestNumElts)
285284
return false;
286285

0 commit comments

Comments
 (0)