diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h --- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -672,7 +672,7 @@ // In case of a vector need to pick the max between the min // required size for each element - auto *VT = cast(Val->getType()); + auto *VT = cast(Val->getType()); // Assume unsigned elements isSigned = false; diff --git a/llvm/include/llvm/Analysis/Utils/Local.h b/llvm/include/llvm/Analysis/Utils/Local.h --- a/llvm/include/llvm/Analysis/Utils/Local.h +++ b/llvm/include/llvm/Analysis/Utils/Local.h @@ -78,7 +78,7 @@ // Splat the index if needed. if (IntIdxTy->isVectorTy() && !Op->getType()->isVectorTy()) Op = Builder->CreateVectorSplat( - cast(IntIdxTy)->getNumElements(), Op); + cast(IntIdxTy)->getNumElements(), Op); // Convert to correct type. if (Op->getType() != IntIdxTy) diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -112,7 +112,7 @@ if (auto *VTy = dyn_cast(C->getType())) { // Handle a vector->scalar integer/fp cast. if (isa(DestTy) || DestTy->isFloatingPointTy()) { - unsigned NumSrcElts = VTy->getNumElements(); + unsigned NumSrcElts = cast(VTy)->getNumElements(); Type *SrcEltTy = VTy->getElementType(); // If the vector is a vector of floating point, convert it to vector of int @@ -155,8 +155,8 @@ return ConstantExpr::getBitCast(C, DestTy); // If the element types match, IR can fold it. - unsigned NumDstElt = DestVTy->getNumElements(); - unsigned NumSrcElt = cast(C->getType())->getNumElements(); + unsigned NumDstElt = cast(DestVTy)->getNumElements(); + unsigned NumSrcElt = cast(C->getType())->getNumElements(); if (NumDstElt == NumSrcElt) return ConstantExpr::getBitCast(C, DestTy); @@ -490,8 +490,8 @@ NumElts = AT->getNumElements(); EltTy = AT->getElementType(); } else { - NumElts = cast(C->getType())->getNumElements(); - EltTy = cast(C->getType())->getElementType(); + NumElts = cast(C->getType())->getNumElements(); + EltTy = cast(C->getType())->getElementType(); } uint64_t EltSize = DL.getTypeAllocSize(EltTy); uint64_t Index = ByteOffset / EltSize; diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1222,7 +1222,8 @@ // If all lanes of a vector shift are undefined the whole shift is. if (isa(C) || isa(C)) { - for (unsigned I = 0, E = cast(C->getType())->getNumElements(); + for (unsigned I = 0, + E = cast(C->getType())->getNumElements(); I != E; ++I) if (!isUndefShift(C->getAggregateElement(I))) return false; @@ -4134,7 +4135,8 @@ Constant *TrueC, *FalseC; if (TrueVal->getType()->isVectorTy() && match(TrueVal, m_Constant(TrueC)) && match(FalseVal, m_Constant(FalseC))) { - unsigned NumElts = cast(TrueC->getType())->getNumElements(); + unsigned NumElts = + cast(TrueC->getType())->getNumElements(); SmallVector NewC; for (unsigned i = 0; i != NumElts; ++i) { // Bail out on incomplete vector constants. @@ -4420,7 +4422,7 @@ if (auto *IdxC = dyn_cast(Idx)) { // For fixed-length vector, fold into undef if index is out of bounds. if (isa(VecVTy) && - IdxC->getValue().uge(VecVTy->getNumElements())) + IdxC->getValue().uge(cast(VecVTy)->getNumElements())) return UndefValue::get(VecVTy->getElementType()); if (Value *Elt = findScalarElement(Vec, IdxC->getZExtValue())) return Elt; @@ -4526,7 +4528,7 @@ return nullptr; // The mask value chooses which source operand we need to look at next. - int InVecNumElts = cast(Op0->getType())->getNumElements(); + int InVecNumElts = cast(Op0->getType())->getNumElements(); int RootElt = MaskVal; Value *SourceOp = Op0; if (MaskVal >= InVecNumElts) { diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp --- a/llvm/lib/Analysis/Lint.cpp +++ b/llvm/lib/Analysis/Lint.cpp @@ -567,7 +567,8 @@ // For a vector, KnownZero will only be true if all values are zero, so check // this per component - for (unsigned I = 0, N = VecTy->getNumElements(); I != N; ++I) { + for (unsigned I = 0, N = cast(VecTy)->getNumElements(); + I != N; ++I) { Constant *Elem = C->getAggregateElement(I); if (isa(Elem)) return true; @@ -625,14 +626,17 @@ void Lint::visitExtractElementInst(ExtractElementInst &I) { if (ConstantInt *CI = dyn_cast(findValue(I.getIndexOperand(), /*OffsetOk=*/false))) - Assert(CI->getValue().ult(I.getVectorOperandType()->getNumElements()), - "Undefined result: extractelement index out of range", &I); + Assert( + CI->getValue().ult( + cast(I.getVectorOperandType())->getNumElements()), + "Undefined result: extractelement index out of range", &I); } void Lint::visitInsertElementInst(InsertElementInst &I) { if (ConstantInt *CI = dyn_cast(findValue(I.getOperand(2), /*OffsetOk=*/false))) - Assert(CI->getValue().ult(I.getType()->getNumElements()), + Assert(CI->getValue().ult( + cast(I.getType())->getNumElements()), "Undefined result: insertelement index out of range", &I); } diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp --- a/llvm/lib/Analysis/TargetTransformInfo.cpp +++ b/llvm/lib/Analysis/TargetTransformInfo.cpp @@ -989,7 +989,8 @@ else if (!SI) return false; - SmallVector Mask(SI->getType()->getNumElements(), -1); + SmallVector Mask( + cast(SI->getType())->getNumElements(), -1); // Build a mask of 0, 2, ... (left) or 1, 3, ... (right) depending on whether // we look at the left or right side. @@ -1128,7 +1129,7 @@ if (!RD) return TTI::RK_None; - auto *VecTy = cast(RdxStart->getType()); + auto *VecTy = cast(RdxStart->getType()); unsigned NumVecElems = VecTy->getNumElements(); if (!isPowerOf2_32(NumVecElems)) return TTI::RK_None; @@ -1193,7 +1194,7 @@ if (!RD) return TTI::RK_None; - auto *VecTy = cast(ReduxRoot->getOperand(0)->getType()); + auto *VecTy = cast(ReduxRoot->getOperand(0)->getType()); unsigned NumVecElems = VecTy->getNumElements(); if (!isPowerOf2_32(NumVecElems)) return TTI::RK_None; diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -172,8 +172,8 @@ return false; int NumElts = - cast(Shuf->getOperand(0)->getType())->getNumElements(); - int NumMaskElts = Shuf->getType()->getNumElements(); + cast(Shuf->getOperand(0)->getType())->getNumElements(); + int NumMaskElts = cast(Shuf->getType())->getNumElements(); DemandedLHS = DemandedRHS = APInt::getNullValue(NumElts); if (DemandedElts.isNullValue()) return true; @@ -3489,9 +3489,10 @@ } // try to handle fixed width vector constants - if (isa(V->getType()) && isa(V)) { + auto *VFVTy = dyn_cast(V->getType()); + if (VFVTy && isa(V)) { // For vectors, verify that each element is not infinity. - unsigned NumElts = cast(V->getType())->getNumElements(); + unsigned NumElts = VFVTy->getNumElements(); for (unsigned i = 0; i != NumElts; ++i) { Constant *Elt = cast(V)->getAggregateElement(i); if (!Elt) @@ -3593,9 +3594,10 @@ } // Try to handle fixed width vector constants - if (isa(V->getType()) && isa(V)) { + auto *VFVTy = dyn_cast(V->getType()); + if (VFVTy && isa(V)) { // For vectors, verify that each element is not NaN. - unsigned NumElts = cast(V->getType())->getNumElements(); + unsigned NumElts = VFVTy->getNumElements(); for (unsigned i = 0; i != NumElts; ++i) { Constant *Elt = cast(V)->getAggregateElement(i); if (!Elt) diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp --- a/llvm/lib/Analysis/VectorUtils.cpp +++ b/llvm/lib/Analysis/VectorUtils.cpp @@ -817,8 +817,8 @@ VecTy1->getScalarType() == VecTy2->getScalarType() && "Expect two vectors with the same element type"); - unsigned NumElts1 = VecTy1->getNumElements(); - unsigned NumElts2 = VecTy2->getNumElements(); + unsigned NumElts1 = cast(VecTy1)->getNumElements(); + unsigned NumElts2 = cast(VecTy2)->getNumElements(); assert(NumElts1 >= NumElts2 && "Unexpect the first vector has less elements"); if (NumElts1 > NumElts2) { @@ -866,8 +866,9 @@ return false; if (ConstMask->isNullValue() || isa(ConstMask)) return true; - for (unsigned I = 0, - E = cast(ConstMask->getType())->getNumElements(); + for (unsigned + I = 0, + E = cast(ConstMask->getType())->getNumElements(); I != E; ++I) { if (auto *MaskElt = ConstMask->getAggregateElement(I)) if (MaskElt->isNullValue() || isa(MaskElt)) @@ -884,8 +885,9 @@ return false; if (ConstMask->isAllOnesValue() || isa(ConstMask)) return true; - for (unsigned I = 0, - E = cast(ConstMask->getType())->getNumElements(); + for (unsigned + I = 0, + E = cast(ConstMask->getType())->getNumElements(); I != E; ++I) { if (auto *MaskElt = ConstMask->getAggregateElement(I)) if (MaskElt->isAllOnesValue() || isa(MaskElt)) @@ -899,7 +901,8 @@ /// vectors. Is there something we can common this with? APInt llvm::possiblyDemandedEltsInMask(Value *Mask) { - const unsigned VWidth = cast(Mask->getType())->getNumElements(); + const unsigned VWidth = + cast(Mask->getType())->getNumElements(); APInt DemandedElts = APInt::getAllOnesValue(VWidth); if (auto *CV = dyn_cast(Mask)) for (unsigned i = 0; i < VWidth; i++)