diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -5329,7 +5329,7 @@ if (!RewriteGEP && Ops.size() == 2) return false; - unsigned NumElts = cast(Ptr->getType())->getNumElements(); + unsigned NumElts = cast(Ptr->getType())->getNumElements(); IRBuilder<> Builder(MemoryInst); @@ -6628,7 +6628,7 @@ if (!NewType) return false; - VectorType *SVIVecType = cast(SVI->getType()); + auto *SVIVecType = cast(SVI->getType()); assert(!NewType->isVectorTy() && "Expected a scalar type!"); assert(NewType->getScalarSizeInBits() == SVIVecType->getScalarSizeInBits() && "Expected a type of the same size!"); diff --git a/llvm/lib/CodeGen/ExpandReductions.cpp b/llvm/lib/CodeGen/ExpandReductions.cpp --- a/llvm/lib/CodeGen/ExpandReductions.cpp +++ b/llvm/lib/CodeGen/ExpandReductions.cpp @@ -125,7 +125,8 @@ if (!FMF.allowReassoc()) Rdx = getOrderedReduction(Builder, Acc, Vec, getOpcode(ID), MRK); else { - if (!isPowerOf2_32(cast(Vec->getType())->getNumElements())) + if (!isPowerOf2_32( + cast(Vec->getType())->getNumElements())) continue; Rdx = getShuffleReduction(Builder, Vec, getOpcode(ID), MRK); @@ -146,7 +147,8 @@ case Intrinsic::experimental_vector_reduce_fmax: case Intrinsic::experimental_vector_reduce_fmin: { Value *Vec = II->getArgOperand(0); - if (!isPowerOf2_32(cast(Vec->getType())->getNumElements())) + if (!isPowerOf2_32( + cast(Vec->getType())->getNumElements())) continue; Rdx = getShuffleReduction(Builder, Vec, getOpcode(ID), MRK); diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -1059,7 +1059,7 @@ // splat vector. unsigned VectorWidth = 0; if (auto *VT = dyn_cast(U.getType())) - VectorWidth = VT->getNumElements(); + VectorWidth = cast(VT)->getNumElements(); // We might need to splat the base pointer into a vector if the offsets // are vectors. @@ -1946,7 +1946,7 @@ MachineIRBuilder &MIRBuilder) { // If it is a <1 x Ty> vector, use the scalar as it is // not a legal vector type in LLT. - if (cast(U.getType())->getNumElements() == 1) + if (cast(U.getType())->getNumElements() == 1) return translateCopy(U, *U.getOperand(1), MIRBuilder); Register Res = getOrCreateVReg(U); @@ -1961,7 +1961,7 @@ MachineIRBuilder &MIRBuilder) { // If it is a <1 x Ty> vector, use the scalar as it is // not a legal vector type in LLT. - if (cast(U.getOperand(0)->getType())->getNumElements() == 1) + if (cast(U.getOperand(0)->getType())->getNumElements() == 1) return translateCopy(U, *U.getOperand(0), MIRBuilder); Register Res = getOrCreateVReg(U); diff --git a/llvm/lib/CodeGen/InterleavedAccessPass.cpp b/llvm/lib/CodeGen/InterleavedAccessPass.cpp --- a/llvm/lib/CodeGen/InterleavedAccessPass.cpp +++ b/llvm/lib/CodeGen/InterleavedAccessPass.cpp @@ -280,7 +280,7 @@ bool InterleavedAccess::lowerInterleavedLoad( LoadInst *LI, SmallVector &DeadInsts) { - if (!LI->isSimple()) + if (!LI->isSimple() || isa(LI->getType())) return false; SmallVector Shuffles; @@ -308,7 +308,8 @@ unsigned Factor, Index; - unsigned NumLoadElements = cast(LI->getType())->getNumElements(); + unsigned NumLoadElements = + cast(LI->getType())->getNumElements(); // Check if the first shufflevector is DE-interleave shuffle. if (!isDeInterleaveMask(Shuffles[0]->getShuffleMask(), Factor, Index, MaxFactor, NumLoadElements)) @@ -421,13 +422,13 @@ return false; ShuffleVectorInst *SVI = dyn_cast(SI->getValueOperand()); - if (!SVI || !SVI->hasOneUse()) + if (!SVI || !SVI->hasOneUse() || isa(SVI->getType())) return false; // Check if the shufflevector is RE-interleave shuffle. unsigned Factor; unsigned OpNumElts = - cast(SVI->getOperand(0)->getType())->getNumElements(); + cast(SVI->getOperand(0)->getType())->getNumElements(); if (!isReInterleaveMask(SVI->getShuffleMask(), Factor, MaxFactor, OpNumElts)) return false; diff --git a/llvm/lib/CodeGen/InterleavedLoadCombinePass.cpp b/llvm/lib/CodeGen/InterleavedLoadCombinePass.cpp --- a/llvm/lib/CodeGen/InterleavedLoadCombinePass.cpp +++ b/llvm/lib/CodeGen/InterleavedLoadCombinePass.cpp @@ -1200,7 +1200,8 @@ IRBuilder<> Builder(InsertionPoint); Type *ETy = InterleavedLoad.front().SVI->getType()->getElementType(); unsigned ElementsPerSVI = - InterleavedLoad.front().SVI->getType()->getNumElements(); + cast(InterleavedLoad.front().SVI->getType()) + ->getNumElements(); FixedVectorType *ILTy = FixedVectorType::get(ETy, Factor * ElementsPerSVI); SmallVector Indices; diff --git a/llvm/lib/CodeGen/LowLevelType.cpp b/llvm/lib/CodeGen/LowLevelType.cpp --- a/llvm/lib/CodeGen/LowLevelType.cpp +++ b/llvm/lib/CodeGen/LowLevelType.cpp @@ -19,7 +19,7 @@ LLT llvm::getLLTForType(Type &Ty, const DataLayout &DL) { if (auto VTy = dyn_cast(&Ty)) { - auto NumElements = VTy->getNumElements(); + auto NumElements = cast(VTy)->getNumElements(); LLT ScalarTy = getLLTForType(*VTy->getElementType(), DL); if (NumElements == 1) return ScalarTy; diff --git a/llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp b/llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp --- a/llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp +++ b/llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp @@ -83,7 +83,7 @@ if (!C) return false; - unsigned NumElts = cast(Mask->getType())->getNumElements(); + unsigned NumElts = cast(Mask->getType())->getNumElements(); for (unsigned i = 0; i != NumElts; ++i) { Constant *CElt = C->getAggregateElement(i); if (!CElt || !isa(CElt)) @@ -132,7 +132,7 @@ Value *Src0 = CI->getArgOperand(3); const Align AlignVal = cast(Alignment)->getAlignValue(); - VectorType *VecType = cast(CI->getType()); + VectorType *VecType = cast(CI->getType()); Type *EltTy = VecType->getElementType(); @@ -158,7 +158,7 @@ Type *NewPtrType = EltTy->getPointerTo(Ptr->getType()->getPointerAddressSpace()); Value *FirstEltPtr = Builder.CreateBitCast(Ptr, NewPtrType); - unsigned VectorWidth = VecType->getNumElements(); + unsigned VectorWidth = cast(VecType)->getNumElements(); // The result vector Value *VResult = Src0; @@ -271,7 +271,7 @@ Value *Mask = CI->getArgOperand(3); const Align AlignVal = cast(Alignment)->getAlignValue(); - VectorType *VecType = cast(Src->getType()); + auto *VecType = cast(Src->getType()); Type *EltTy = VecType->getElementType(); @@ -295,7 +295,7 @@ Type *NewPtrType = EltTy->getPointerTo(Ptr->getType()->getPointerAddressSpace()); Value *FirstEltPtr = Builder.CreateBitCast(Ptr, NewPtrType); - unsigned VectorWidth = VecType->getNumElements(); + unsigned VectorWidth = cast(VecType)->getNumElements(); if (isConstantIntVector(Mask)) { for (unsigned Idx = 0; Idx < VectorWidth; ++Idx) { @@ -396,7 +396,7 @@ Value *Mask = CI->getArgOperand(2); Value *Src0 = CI->getArgOperand(3); - VectorType *VecType = cast(CI->getType()); + auto *VecType = cast(CI->getType()); Type *EltTy = VecType->getElementType(); IRBuilder<> Builder(CI->getContext()); @@ -520,8 +520,8 @@ Value *Alignment = CI->getArgOperand(2); Value *Mask = CI->getArgOperand(3); - assert(isa(Src->getType()) && - "Unexpected data type in masked scatter intrinsic"); + auto *SrcFVTy = cast(Src->getType()); + assert( isa(Ptrs->getType()) && isa(cast(Ptrs->getType())->getElementType()) && @@ -534,7 +534,7 @@ Builder.SetCurrentDebugLocation(CI->getDebugLoc()); MaybeAlign AlignVal = cast(Alignment)->getMaybeAlignValue(); - unsigned VectorWidth = cast(Src->getType())->getNumElements(); + unsigned VectorWidth = SrcFVTy->getNumElements(); // Shorten the way if the mask is a vector of constants. if (isConstantIntVector(Mask)) { @@ -605,7 +605,7 @@ Value *Mask = CI->getArgOperand(1); Value *PassThru = CI->getArgOperand(2); - VectorType *VecType = cast(CI->getType()); + auto *VecType = cast(CI->getType()); Type *EltTy = VecType->getElementType(); @@ -718,7 +718,7 @@ Value *Ptr = CI->getArgOperand(1); Value *Mask = CI->getArgOperand(2); - VectorType *VecType = cast(Src->getType()); + auto *VecType = cast(Src->getType()); IRBuilder<> Builder(CI->getContext()); Instruction *InsertPt = CI; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -4295,7 +4295,7 @@ Base = SDB->getValue(C); - unsigned NumElts = cast(Ptr->getType())->getNumElements(); + unsigned NumElts = cast(Ptr->getType())->getNumElements(); EVT VT = EVT::getVectorVT(*DAG.getContext(), TLI.getPointerTy(DL), NumElts); Index = DAG.getConstant(0, SDB->getCurSDLoc(), VT); IndexType = ISD::SIGNED_SCALED; diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1765,7 +1765,7 @@ } else { unsigned NumElements; if (auto *VTy = dyn_cast(Ty)) - NumElements = VTy->getNumElements(); + NumElements = cast(VTy)->getNumElements(); else NumElements = Ty->getArrayNumElements(); std::string HexString; diff --git a/llvm/lib/CodeGen/ValueTypes.cpp b/llvm/lib/CodeGen/ValueTypes.cpp --- a/llvm/lib/CodeGen/ValueTypes.cpp +++ b/llvm/lib/CodeGen/ValueTypes.cpp @@ -122,7 +122,14 @@ unsigned EVT::getExtendedVectorNumElements() const { assert(isExtended() && "Type is not extended!"); - return cast(LLVMTy)->getNumElements(); + ElementCount EC = cast(LLVMTy)->getElementCount(); + if (EC.Scalable) { + WithColor::warning() + << "The code that requested the fixed number of elements has made the " + "assumption that this vector is not scalable. This assumption was " + "not correct, and this may lead to broken code\n"; + } + return EC.Min; } ElementCount EVT::getExtendedVectorElementCount() const {