diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1909,8 +1909,8 @@ Value *InnerLoopVectorizer::getStepVector(Value *Val, int StartIdx, Value *Step, Instruction::BinaryOps BinOp) { // Create and check the types. - assert(Val->getType()->isVectorTy() && "Must be a vector"); - int VLen = Val->getType()->getVectorNumElements(); + auto *ValVTy = cast(Val->getType()); + int VLen = ValVTy->getNumElements(); Type *STy = Val->getType()->getScalarType(); assert((STy->isIntegerTy() || STy->isFloatingPointTy()) && @@ -3322,13 +3322,14 @@ } static Type *smallestIntegerVectorType(Type *T1, Type *T2) { - auto *I1 = cast(T1->getVectorElementType()); - auto *I2 = cast(T2->getVectorElementType()); + auto *I1 = cast(cast(T1)->getElementType()); + auto *I2 = cast(cast(T2)->getElementType()); return I1->getBitWidth() < I2->getBitWidth() ? T1 : T2; } + static Type *largestIntegerVectorType(Type *T1, Type *T2) { - auto *I1 = cast(T1->getVectorElementType()); - auto *I2 = cast(T2->getVectorElementType()); + auto *I1 = cast(cast(T1)->getElementType()); + auto *I2 = cast(cast(T2)->getElementType()); return I1->getBitWidth() > I2->getBitWidth() ? T1 : T2; } @@ -3351,8 +3352,8 @@ Type *OriginalTy = I->getType(); Type *ScalarTruncatedTy = IntegerType::get(OriginalTy->getContext(), KV.second); - Type *TruncatedTy = VectorType::get(ScalarTruncatedTy, - OriginalTy->getVectorNumElements()); + Type *TruncatedTy = VectorType::get( + ScalarTruncatedTy, cast(OriginalTy)->getNumElements()); if (TruncatedTy == OriginalTy) continue; @@ -3402,10 +3403,12 @@ break; } } else if (auto *SI = dyn_cast(I)) { - auto Elements0 = SI->getOperand(0)->getType()->getVectorNumElements(); + auto Elements0 = + cast(SI->getOperand(0)->getType())->getNumElements(); auto *O0 = B.CreateZExtOrTrunc( SI->getOperand(0), VectorType::get(ScalarTruncatedTy, Elements0)); - auto Elements1 = SI->getOperand(1)->getType()->getVectorNumElements(); + auto Elements1 = + cast(SI->getOperand(1)->getType())->getNumElements(); auto *O1 = B.CreateZExtOrTrunc( SI->getOperand(1), VectorType::get(ScalarTruncatedTy, Elements1)); @@ -3414,13 +3417,15 @@ // Don't do anything with the operands, just extend the result. continue; } else if (auto *IE = dyn_cast(I)) { - auto Elements = IE->getOperand(0)->getType()->getVectorNumElements(); + auto Elements = + cast(IE->getOperand(0)->getType())->getNumElements(); auto *O0 = B.CreateZExtOrTrunc( IE->getOperand(0), VectorType::get(ScalarTruncatedTy, Elements)); auto *O1 = B.CreateZExtOrTrunc(IE->getOperand(1), ScalarTruncatedTy); NewI = B.CreateInsertElement(O0, O1, IE->getOperand(2)); } else if (auto *EE = dyn_cast(I)) { - auto Elements = EE->getOperand(0)->getType()->getVectorNumElements(); + auto Elements = + cast(EE->getOperand(0)->getType())->getNumElements(); auto *O0 = B.CreateZExtOrTrunc( EE->getOperand(0), VectorType::get(ScalarTruncatedTy, Elements)); NewI = B.CreateExtractElement(O0, EE->getOperand(2)); diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -285,7 +285,7 @@ static Optional isShuffle(ArrayRef VL) { auto *EI0 = cast(VL[0]); - unsigned Size = EI0->getVectorOperandType()->getVectorNumElements(); + unsigned Size = EI0->getVectorOperandType()->getNumElements(); Value *Vec1 = nullptr; Value *Vec2 = nullptr; enum ShuffleMode { Unknown, Select, Permute }; @@ -294,7 +294,7 @@ auto *EI = cast(VL[I]); auto *Vec = EI->getVectorOperand(); // All vector operands must have the same number of vector elements. - if (Vec->getType()->getVectorNumElements() != Size) + if (cast(Vec->getType())->getNumElements() != Size) return None; auto *Idx = dyn_cast(EI->getIndexOperand()); if (!Idx) @@ -3182,7 +3182,7 @@ if (!LI || !LI->isSimple() || !LI->hasNUses(VL.size())) return false; } else { - NElts = Vec->getType()->getVectorNumElements(); + NElts = cast(Vec->getType())->getNumElements(); } if (NElts != VL.size()) diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -236,10 +236,10 @@ // ShufMask = { 2, undef, undef, undef } uint64_t SplatIndex = ConvertToShuffle == Ext0 ? C0 : C1; uint64_t CheapExtIndex = ConvertToShuffle == Ext0 ? C1 : C0; - Type *VecTy = V0->getType(); + auto *VecTy = cast(V0->getType()); Type *I32Ty = IntegerType::getInt32Ty(I.getContext()); UndefValue *Undef = UndefValue::get(I32Ty); - SmallVector ShufMask(VecTy->getVectorNumElements(), Undef); + SmallVector ShufMask(VecTy->getNumElements(), Undef); ShufMask[CheapExtIndex] = ConstantInt::get(I32Ty, SplatIndex); IRBuilder<> Builder(ConvertToShuffle); @@ -272,15 +272,14 @@ m_Mask(Mask)))))) return false; - Type *DestTy = I.getType(); - Type *SrcTy = V->getType(); - if (!DestTy->isVectorTy() || I.getOperand(0)->getType() != SrcTy) + auto *DestTy = dyn_cast(I.getType()); + auto *SrcTy = cast(V->getType()); + if (!DestTy || I.getOperand(0)->getType() != SrcTy) return false; // TODO: Handle bitcast from narrow element type to wide element type. - assert(SrcTy->isVectorTy() && "Shuffle of non-vector type?"); - unsigned DestNumElts = DestTy->getVectorNumElements(); - unsigned SrcNumElts = SrcTy->getVectorNumElements(); + unsigned DestNumElts = DestTy->getNumElements(); + unsigned SrcNumElts = SrcTy->getNumElements(); if (SrcNumElts > DestNumElts) return false;