// Splat the constant if needed.
if (IntIdxTy->isVectorTy() && !OpC->getType()->isVectorTy())
- OpC = ConstantVector::getSplat(IntIdxTy->getVectorElementCount(), OpC);
+ OpC = ConstantVector::getSplat(
+ cast<VectorType>(IntIdxTy)->getElementCount(), OpC);
Constant *Scale = ConstantInt::get(IntIdxTy, Size);
Constant *OC = ConstantExpr::getIntegerCast(OpC, IntIdxTy, true /*SExt*/);
// Splat the index if needed.
if (IntIdxTy->isVectorTy() && !Op->getType()->isVectorTy())
- Op = Builder->CreateVectorSplat(IntIdxTy->getVectorNumElements(), Op);
+ Op = Builder->CreateVectorSplat(
+ cast<VectorType>(IntIdxTy)->getNumElements(), Op);
// Convert to correct type.
if (Op->getType() != IntIdxTy)
// If the element types match, IR can fold it.
unsigned NumDstElt = DestVTy->getNumElements();
- unsigned NumSrcElt = C->getType()->getVectorNumElements();
+ unsigned NumSrcElt = cast<VectorType>(C->getType())->getNumElements();
if (NumDstElt == NumSrcElt)
return ConstantExpr::getBitCast(C, DestTy);
- Type *SrcEltTy = C->getType()->getVectorElementType();
+ Type *SrcEltTy = cast<VectorType>(C->getType())->getElementType();
Type *DstEltTy = DestVTy->getElementType();
// Otherwise, we're changing the number of elements in a vector, which
for (unsigned j = 0; j != Ratio; ++j) {
Constant *Src = C->getAggregateElement(SrcElt++);
if (Src && isa<UndefValue>(Src))
- Src = Constant::getNullValue(C->getType()->getVectorElementType());
+ Src = Constant::getNullValue(
+ cast<VectorType>(C->getType())->getElementType());
else
Src = dyn_cast_or_null<ConstantInt>(Src);
if (!Src) // Reject constantexpr elements.
NumElts = AT->getNumElements();
EltTy = AT->getElementType();
} else {
- NumElts = C->getType()->getVectorNumElements();
- EltTy = C->getType()->getVectorElementType();
+ NumElts = cast<VectorType>(C->getType())->getNumElements();
+ EltTy = cast<VectorType>(C->getType())->getElementType();
}
uint64_t EltSize = DL.getTypeAllocSize(EltTy);
uint64_t Index = ByteOffset / EltSize;
Constant *FoldReinterpretLoadFromConstPtr(Constant *C, Type *LoadTy,
const DataLayout &DL) {
// Bail out early. Not expect to load from scalable global variable.
- if (LoadTy->isVectorTy() && LoadTy->getVectorIsScalable())
+ if (LoadTy->isVectorTy() && cast<VectorType>(LoadTy)->isScalable())
return nullptr;
auto *PTy = cast<PointerType>(C->getType());
Type *ResElemTy = GEP->getResultElementType();
Type *ResTy = GEP->getType();
if (!SrcElemTy->isSized() ||
- (SrcElemTy->isVectorTy() && SrcElemTy->getVectorIsScalable()))
+ (SrcElemTy->isVectorTy() && cast<VectorType>(SrcElemTy)->isScalable()))
return nullptr;
if (Constant *C = CastGEPIndices(SrcElemTy, Ops, ResTy,
// Do not iterate on scalable vector. The number of elements is unknown at
// compile-time.
- if (VTy->getVectorIsScalable())
+ if (VTy->isScalable())
return nullptr;
if (IntrinsicID == Intrinsic::masked_load) {
// If any element of a constant divisor vector is zero or undef, the whole op
// is undef.
auto *Op1C = dyn_cast<Constant>(Op1);
- if (Op1C && Ty->isVectorTy()) {
- unsigned NumElts = Ty->getVectorNumElements();
+ auto *VTy = dyn_cast<VectorType>(Ty);
+ if (Op1C && VTy) {
+ unsigned NumElts = VTy->getNumElements();
for (unsigned i = 0; i != NumElts; ++i) {
Constant *Elt = Op1C->getAggregateElement(i);
if (Elt && (Elt->isNullValue() || isa<UndefValue>(Elt)))
// If all lanes of a vector shift are undefined the whole shift is.
if (isa<ConstantVector>(C) || isa<ConstantDataVector>(C)) {
- for (unsigned I = 0, E = C->getType()->getVectorNumElements(); I != E; ++I)
+ for (unsigned I = 0, E = cast<VectorType>(C->getType())->getNumElements();
+ I != E; ++I)
if (!isUndefShift(C->getAggregateElement(I)))
return false;
return true;
Constant *TrueC, *FalseC;
if (TrueVal->getType()->isVectorTy() && match(TrueVal, m_Constant(TrueC)) &&
match(FalseVal, m_Constant(FalseC))) {
- unsigned NumElts = TrueC->getType()->getVectorNumElements();
+ unsigned NumElts = cast<VectorType>(TrueC->getType())->getNumElements();
SmallVector<Constant *, 16> NewC;
for (unsigned i = 0; i != NumElts; ++i) {
// Bail out on incomplete vector constants.
return UndefValue::get(GEPTy);
bool IsScalableVec =
- SrcTy->isVectorTy() ? SrcTy->getVectorIsScalable() : false;
+ isa<VectorType>(SrcTy) && cast<VectorType>(SrcTy)->isScalable();
if (Ops.size() == 2) {
// getelementptr P, 0 -> P.
// For fixed-length vector, fold into undef if index is out of bounds.
if (auto *CI = dyn_cast<ConstantInt>(Idx)) {
- if (!Vec->getType()->getVectorIsScalable() &&
- CI->uge(Vec->getType()->getVectorNumElements()))
+ if (!cast<VectorType>(Vec->getType())->isScalable() &&
+ CI->uge(cast<VectorType>(Vec->getType())->getNumElements()))
return UndefValue::get(Vec->getType());
}
/// If not, this returns null.
static Value *SimplifyExtractElementInst(Value *Vec, Value *Idx, const SimplifyQuery &,
unsigned) {
+ auto *VecVTy = cast<VectorType>(Vec->getType());
if (auto *CVec = dyn_cast<Constant>(Vec)) {
if (auto *CIdx = dyn_cast<Constant>(Idx))
return ConstantFoldExtractElementInstruction(CVec, CIdx);
return Splat;
if (isa<UndefValue>(Vec))
- return UndefValue::get(Vec->getType()->getVectorElementType());
+ return UndefValue::get(VecVTy->getElementType());
}
// If extracting a specified index from the vector, see if we can recursively
// find a previously computed scalar that was inserted into the vector.
if (auto *IdxC = dyn_cast<ConstantInt>(Idx)) {
// For fixed-length vector, fold into undef if index is out of bounds.
- if (!Vec->getType()->getVectorIsScalable() &&
- IdxC->getValue().uge(Vec->getType()->getVectorNumElements()))
- return UndefValue::get(Vec->getType()->getVectorElementType());
+ if (!VecVTy->isScalable() && IdxC->getValue().uge(VecVTy->getNumElements()))
+ return UndefValue::get(VecVTy->getElementType());
if (Value *Elt = findScalarElement(Vec, IdxC->getZExtValue()))
return Elt;
}
// An undef extract index can be arbitrarily chosen to be an out-of-range
// index value, which would result in the instruction being undef.
if (isa<UndefValue>(Idx))
- return UndefValue::get(Vec->getType()->getVectorElementType());
+ return UndefValue::get(VecVTy->getElementType());
return nullptr;
}
return nullptr;
// The mask value chooses which source operand we need to look at next.
- int InVecNumElts = Op0->getType()->getVectorNumElements();
+ int InVecNumElts = cast<VectorType>(Op0->getType())->getNumElements();
int RootElt = MaskVal;
Value *SourceOp = Op0;
if (MaskVal >= InVecNumElts) {
if (all_of(Mask, [](int Elem) { return Elem == UndefMaskElem; }))
return UndefValue::get(RetTy);
- Type *InVecTy = Op0->getType();
+ auto *InVecTy = cast<VectorType>(Op0->getType());
unsigned MaskNumElts = Mask.size();
- ElementCount InVecEltCount = InVecTy->getVectorElementCount();
+ ElementCount InVecEltCount = InVecTy->getElementCount();
bool Scalable = InVecEltCount.Scalable;
const DominatorTree *DT) {
// For unsized types or scalable vectors we don't know exactly how many bytes
// are dereferenced, so bail out.
- if (!Ty->isSized() || (Ty->isVectorTy() && Ty->getVectorIsScalable()))
+ if (!Ty->isSized() ||
+ (Ty->isVectorTy() && cast<VectorType>(Ty)->isScalable()))
return false;
// When dereferenceability information is provided by a dereferenceable
return unknown();
if (I.getAllocatedType()->isVectorTy() &&
- I.getAllocatedType()->getVectorIsScalable())
+ cast<VectorType>(I.getAllocatedType())->isScalable())
return unknown();
APInt Size(IntTyBits, DL.getTypeAllocSize(I.getAllocatedType()));
else if (!SI)
return false;
- SmallVector<int, 32> Mask(SI->getType()->getVectorNumElements(), -1);
+ SmallVector<int, 32> Mask(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.
if (!RD)
return RK_None;
- Type *VecTy = RdxStart->getType();
- unsigned NumVecElems = VecTy->getVectorNumElements();
+ auto *VecTy = cast<VectorType>(RdxStart->getType());
+ unsigned NumVecElems = VecTy->getNumElements();
if (!isPowerOf2_32(NumVecElems))
return RK_None;
if (!RD)
return RK_None;
- Type *VecTy = ReduxRoot->getOperand(0)->getType();
- unsigned NumVecElems = VecTy->getVectorNumElements();
+ auto *VecTy = cast<VectorType>(ReduxRoot->getOperand(0)->getType());
+ unsigned NumVecElems = VecTy->getNumElements();
if (!isPowerOf2_32(NumVecElems))
return RK_None;
APInt &DemandedLHS, APInt &DemandedRHS) {
// The length of scalable vectors is unknown at compile time, thus we
// cannot check their values
- if (Shuf->getType()->getVectorElementCount().Scalable)
+ if (Shuf->getType()->isScalable())
return false;
- int NumElts = Shuf->getOperand(0)->getType()->getVectorNumElements();
- int NumMaskElts = Shuf->getType()->getVectorNumElements();
+ int NumElts =
+ cast<VectorType>(Shuf->getOperand(0)->getType())->getNumElements();
+ int NumMaskElts = Shuf->getType()->getNumElements();
DemandedLHS = DemandedRHS = APInt::getNullValue(NumElts);
if (DemandedElts.isNullValue())
return true;
static void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
const Query &Q) {
Type *Ty = V->getType();
- APInt DemandedElts = Ty->isVectorTy()
- ? APInt::getAllOnesValue(Ty->getVectorNumElements())
- : APInt(1, 1);
+ APInt DemandedElts =
+ Ty->isVectorTy()
+ ? APInt::getAllOnesValue(cast<VectorType>(Ty)->getNumElements())
+ : APInt(1, 1);
computeKnownBits(V, DemandedElts, Known, Depth, Q);
}
static unsigned ComputeNumSignBits(const Value *V, unsigned Depth,
const Query &Q) {
Type *Ty = V->getType();
- APInt DemandedElts = Ty->isVectorTy()
- ? APInt::getAllOnesValue(Ty->getVectorNumElements())
- : APInt(1, 1);
+ APInt DemandedElts =
+ Ty->isVectorTy()
+ ? APInt::getAllOnesValue(cast<VectorType>(Ty)->getNumElements())
+ : APInt(1, 1);
return ComputeNumSignBits(V, DemandedElts, Depth, Q);
}
const Value *Vec = I->getOperand(0);
const Value *Idx = I->getOperand(1);
auto *CIdx = dyn_cast<ConstantInt>(Idx);
- unsigned NumElts = Vec->getType()->getVectorNumElements();
+ unsigned NumElts = cast<VectorType>(Vec->getType())->getNumElements();
APInt DemandedVecElts = APInt::getAllOnesValue(NumElts);
if (CIdx && CIdx->getValue().ult(NumElts))
DemandedVecElts = APInt::getOneBitSet(NumElts, CIdx->getZExtValue());
Type *Ty = V->getType();
assert((Ty->isIntOrIntVectorTy(BitWidth) || Ty->isPtrOrPtrVectorTy()) &&
"Not integer or pointer type!");
- assert(((Ty->isVectorTy() &&
- Ty->getVectorNumElements() == DemandedElts.getBitWidth()) ||
+ assert(((Ty->isVectorTy() && cast<VectorType>(Ty)->getNumElements() ==
+ DemandedElts.getBitWidth()) ||
(!Ty->isVectorTy() && DemandedElts == APInt(1, 1))) &&
"Unexpected vector size");
const Value *Vec = EEI->getVectorOperand();
const Value *Idx = EEI->getIndexOperand();
auto *CIdx = dyn_cast<ConstantInt>(Idx);
- unsigned NumElts = Vec->getType()->getVectorNumElements();
+ unsigned NumElts = cast<VectorType>(Vec->getType())->getNumElements();
APInt DemandedVecElts = APInt::getAllOnesValue(NumElts);
if (CIdx && CIdx->getValue().ult(NumElts))
DemandedVecElts = APInt::getOneBitSet(NumElts, CIdx->getZExtValue());
bool isKnownNonZero(const Value* V, unsigned Depth, const Query& Q) {
Type *Ty = V->getType();
- APInt DemandedElts = Ty->isVectorTy()
- ? APInt::getAllOnesValue(Ty->getVectorNumElements())
- : APInt(1, 1);
+ APInt DemandedElts =
+ Ty->isVectorTy()
+ ? APInt::getAllOnesValue(cast<VectorType>(Ty)->getNumElements())
+ : APInt(1, 1);
return isKnownNonZero(V, DemandedElts, Depth, Q);
}
return 0;
unsigned MinSignBits = TyBits;
- unsigned NumElts = CV->getType()->getVectorNumElements();
+ unsigned NumElts = cast<VectorType>(CV->getType())->getNumElements();
for (unsigned i = 0; i != NumElts; ++i) {
if (!DemandedElts[i])
continue;
// same behavior for poison though -- that's a FIXME today.
Type *Ty = V->getType();
- assert(((Ty->isVectorTy() &&
- Ty->getVectorNumElements() == DemandedElts.getBitWidth()) ||
+ assert(((Ty->isVectorTy() && cast<VectorType>(Ty)->getNumElements() ==
+ DemandedElts.getBitWidth()) ||
(!Ty->isVectorTy() && DemandedElts == APInt(1, 1))) &&
"Unexpected vector size");
// Handle vector of constants.
if (auto *CV = dyn_cast<Constant>(V)) {
- if (CV->getType()->isVectorTy()) {
- unsigned NumElts = CV->getType()->getVectorNumElements();
+ if (auto *CVVTy = dyn_cast<VectorType>(CV->getType())) {
+ unsigned NumElts = CVVTy->getNumElements();
for (unsigned i = 0; i != NumElts; ++i) {
auto *CFP = dyn_cast_or_null<ConstantFP>(CV->getAggregateElement(i));
if (!CFP)
return false;
// For vectors, verify that each element is not infinity.
- unsigned NumElts = V->getType()->getVectorNumElements();
+ unsigned NumElts = cast<VectorType>(V->getType())->getNumElements();
for (unsigned i = 0; i != NumElts; ++i) {
Constant *Elt = cast<Constant>(V)->getAggregateElement(i);
if (!Elt)
return false;
// For vectors, verify that each element is not NaN.
- unsigned NumElts = V->getType()->getVectorNumElements();
+ unsigned NumElts = cast<VectorType>(V->getType())->getNumElements();
for (unsigned i = 0; i != NumElts; ++i) {
Constant *Elt = cast<Constant>(V)->getAggregateElement(i);
if (!Elt)
assert(V->getType()->isVectorTy() && "Not looking at a vector?");
VectorType *VTy = cast<VectorType>(V->getType());
// For fixed-length vector, return undef for out of range access.
- if (!V->getType()->getVectorIsScalable()) {
+ if (!VTy->isScalable()) {
unsigned Width = VTy->getNumElements();
if (EltNo >= Width)
return UndefValue::get(VTy->getElementType());
}
if (ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(V)) {
- unsigned LHSWidth = SVI->getOperand(0)->getType()->getVectorNumElements();
+ unsigned LHSWidth =
+ cast<VectorType>(SVI->getOperand(0)->getType())->getNumElements();
int InEl = SVI->getMaskValue(EltNo);
if (InEl < 0)
return UndefValue::get(VTy->getElementType());
return false;
if (ConstMask->isNullValue() || isa<UndefValue>(ConstMask))
return true;
- for (unsigned I = 0, E = ConstMask->getType()->getVectorNumElements(); I != E;
- ++I) {
+ for (unsigned I = 0,
+ E = cast<VectorType>(ConstMask->getType())->getNumElements();
+ I != E; ++I) {
if (auto *MaskElt = ConstMask->getAggregateElement(I))
if (MaskElt->isNullValue() || isa<UndefValue>(MaskElt))
continue;
return false;
if (ConstMask->isAllOnesValue() || isa<UndefValue>(ConstMask))
return true;
- for (unsigned I = 0, E = ConstMask->getType()->getVectorNumElements(); I != E;
- ++I) {
+ for (unsigned I = 0,
+ E = cast<VectorType>(ConstMask->getType())->getNumElements();
+ I != E; ++I) {
if (auto *MaskElt = ConstMask->getAggregateElement(I))
if (MaskElt->isAllOnesValue() || isa<UndefValue>(MaskElt))
continue;