Skip to content

Commit 3ecced1

Browse files
[SVE] Remove calls to isScalable from IR
Reviewers: efriedma, sdesmalen, dexonsmith, dblaikie Reviewed By: sdesmalen Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77691
1 parent 757c7c2 commit 3ecced1

12 files changed

+57
-67
lines changed

llvm/include/llvm/IR/GetElementPtrTypeIterator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace llvm {
8080
NumElements = ATy->getNumElements();
8181
} else if (auto *VTy = dyn_cast<VectorType>(Ty)) {
8282
CurTy = VTy->getElementType();
83-
if (VTy->isScalable())
83+
if (isa<ScalableVectorType>(VTy))
8484
NumElements = Unbounded;
8585
else
8686
NumElements = VTy->getNumElements();

llvm/include/llvm/IR/PatternMatch.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -2173,8 +2173,8 @@ struct VScaleVal_match {
21732173

21742174
if (m_PtrToInt(m_OffsetGep(m_Zero(), m_SpecificInt(1))).match(V)) {
21752175
Type *PtrTy = cast<Operator>(V)->getOperand(0)->getType();
2176-
auto *DerefTy = dyn_cast<VectorType>(PtrTy->getPointerElementType());
2177-
if (DerefTy && DerefTy->isScalable() &&
2176+
auto *DerefTy = PtrTy->getPointerElementType();
2177+
if (isa<ScalableVectorType>(DerefTy) &&
21782178
DL.getTypeAllocSizeInBits(DerefTy).getKnownMinSize() == 8)
21792179
return true;
21802180
}

llvm/lib/IR/AsmWriter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ static void PrintLLVMName(raw_ostream &OS, const Value *V) {
464464

465465
static void PrintShuffleMask(raw_ostream &Out, Type *Ty, ArrayRef<int> Mask) {
466466
Out << ", <";
467-
if (cast<VectorType>(Ty)->isScalable())
467+
if (isa<ScalableVectorType>(Ty))
468468
Out << "vscale x ";
469469
Out << Mask.size() << " x i32> ";
470470
bool FirstElt = true;

llvm/lib/IR/ConstantFold.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static Constant *BitCastConstantVector(Constant *CV, VectorType *DstTy) {
4949

5050
// Do not iterate on scalable vector. The num of elements is unknown at
5151
// compile-time.
52-
if (DstTy->isScalable())
52+
if (isa<ScalableVectorType>(DstTy))
5353
return nullptr;
5454

5555
// If this cast changes element count then we can't handle it here:
@@ -848,7 +848,7 @@ Constant *llvm::ConstantFoldInsertElementInstruction(Constant *Val,
848848
// Do not iterate on scalable vector. The num of elements is unknown at
849849
// compile-time.
850850
VectorType *ValTy = cast<VectorType>(Val->getType());
851-
if (ValTy->isScalable())
851+
if (isa<ScalableVectorType>(ValTy))
852852
return nullptr;
853853

854854
unsigned NumElts = cast<VectorType>(Val->getType())->getNumElements();
@@ -876,7 +876,7 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2,
876876
ArrayRef<int> Mask) {
877877
auto *V1VTy = cast<VectorType>(V1->getType());
878878
unsigned MaskNumElts = Mask.size();
879-
ElementCount MaskEltCount = {MaskNumElts, V1VTy->isScalable()};
879+
ElementCount MaskEltCount = {MaskNumElts, isa<ScalableVectorType>(V1VTy)};
880880
Type *EltTy = V1VTy->getElementType();
881881

882882
// Undefined shuffle mask -> undefined value.
@@ -895,7 +895,7 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2,
895895
}
896896
// Do not iterate on scalable vector. The num of elements is unknown at
897897
// compile-time.
898-
if (V1VTy->isScalable())
898+
if (isa<ScalableVectorType>(V1VTy))
899899
return nullptr;
900900

901901
unsigned SrcNumElts = V1VTy->getNumElements();
@@ -972,8 +972,7 @@ Constant *llvm::ConstantFoldUnaryInstruction(unsigned Opcode, Constant *C) {
972972

973973
// Handle scalar UndefValue and scalable vector UndefValue. Fixed-length
974974
// vectors are always evaluated per element.
975-
bool IsScalableVector = isa<VectorType>(C->getType()) &&
976-
cast<VectorType>(C->getType())->isScalable();
975+
bool IsScalableVector = isa<ScalableVectorType>(C->getType());
977976
bool HasScalarUndefOrScalableVectorUndef =
978977
(!C->getType()->isVectorTy() || IsScalableVector) && isa<UndefValue>(C);
979978

@@ -1046,8 +1045,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
10461045

10471046
// Handle scalar UndefValue and scalable vector UndefValue. Fixed-length
10481047
// vectors are always evaluated per element.
1049-
bool IsScalableVector = isa<VectorType>(C1->getType()) &&
1050-
cast<VectorType>(C1->getType())->isScalable();
1048+
bool IsScalableVector = isa<ScalableVectorType>(C1->getType());
10511049
bool HasScalarUndefOrScalableVectorUndef =
10521050
(!C1->getType()->isVectorTy() || IsScalableVector) &&
10531051
(isa<UndefValue>(C1) || isa<UndefValue>(C2));
@@ -2000,7 +1998,7 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
20001998

20011999
// Do not iterate on scalable vector. The number of elements is unknown at
20022000
// compile-time.
2003-
if (C1VTy->isScalable())
2001+
if (isa<ScalableVectorType>(C1VTy))
20042002
return nullptr;
20052003

20062004
// Fast path for splatted constants.

llvm/lib/IR/Constants.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ bool Constant::isFiniteNonZeroFP() const {
241241
bool Constant::isNormalFP() const {
242242
if (auto *CFP = dyn_cast<ConstantFP>(this))
243243
return CFP->getValueAPF().isNormal();
244-
auto *VTy = dyn_cast<VectorType>(getType());
244+
auto *VTy = dyn_cast<FixedVectorType>(getType());
245245
if (!VTy)
246246
return false;
247247
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
@@ -255,7 +255,7 @@ bool Constant::isNormalFP() const {
255255
bool Constant::hasExactInverseFP() const {
256256
if (auto *CFP = dyn_cast<ConstantFP>(this))
257257
return CFP->getValueAPF().getExactInverse(nullptr);
258-
auto *VTy = dyn_cast<VectorType>(getType());
258+
auto *VTy = dyn_cast<FixedVectorType>(getType());
259259
if (!VTy)
260260
return false;
261261
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
@@ -269,7 +269,7 @@ bool Constant::hasExactInverseFP() const {
269269
bool Constant::isNaN() const {
270270
if (auto *CFP = dyn_cast<ConstantFP>(this))
271271
return CFP->isNaN();
272-
auto *VTy = dyn_cast<VectorType>(getType());
272+
auto *VTy = dyn_cast<FixedVectorType>(getType());
273273
if (!VTy)
274274
return false;
275275
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
@@ -644,7 +644,7 @@ Constant *Constant::replaceUndefsWith(Constant *C, Constant *Replacement) {
644644
}
645645

646646
// Don't know how to deal with this constant.
647-
auto *VTy = dyn_cast<VectorType>(Ty);
647+
auto *VTy = dyn_cast<FixedVectorType>(Ty);
648648
if (!VTy)
649649
return C;
650650

@@ -2287,7 +2287,7 @@ Constant *ConstantExpr::getShuffleVector(Constant *V1, Constant *V2,
22872287
unsigned NElts = Mask.size();
22882288
auto V1VTy = cast<VectorType>(V1->getType());
22892289
Type *EltTy = V1VTy->getElementType();
2290-
bool TypeIsScalable = V1VTy->isScalable();
2290+
bool TypeIsScalable = isa<ScalableVectorType>(V1VTy);
22912291
Type *ShufTy = VectorType::get(EltTy, NElts, TypeIsScalable);
22922292

22932293
if (OnlyIfReducedTy == ShufTy)

llvm/lib/IR/ConstantsContext.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,10 @@ class InsertElementConstantExpr : public ConstantExpr {
148148
class ShuffleVectorConstantExpr : public ConstantExpr {
149149
public:
150150
ShuffleVectorConstantExpr(Constant *C1, Constant *C2, ArrayRef<int> Mask)
151-
: ConstantExpr(
152-
VectorType::get(cast<VectorType>(C1->getType())->getElementType(),
153-
Mask.size(),
154-
cast<VectorType>(C1->getType())->isScalable()),
155-
Instruction::ShuffleVector, &Op<0>(), 2) {
151+
: ConstantExpr(VectorType::get(
152+
cast<VectorType>(C1->getType())->getElementType(),
153+
Mask.size(), isa<ScalableVectorType>(C1->getType())),
154+
Instruction::ShuffleVector, &Op<0>(), 2) {
156155
assert(ShuffleVectorInst::isValidOperands(C1, C2, Mask) &&
157156
"Invalid shuffle vector instruction operands!");
158157
Op<0>() = C1;

llvm/lib/IR/Function.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1354,10 +1354,9 @@ static bool matchIntrinsicType(
13541354
return true;
13551355
}
13561356
case IITDescriptor::ScalableVecArgument: {
1357-
VectorType *VTy = dyn_cast<VectorType>(Ty);
1358-
if (!VTy || !VTy->isScalable())
1357+
if (!isa<ScalableVectorType>(Ty))
13591358
return true;
1360-
return matchIntrinsicType(VTy, Infos, ArgTys, DeferredChecks,
1359+
return matchIntrinsicType(Ty, Infos, ArgTys, DeferredChecks,
13611360
IsDeferredCheck);
13621361
}
13631362
case IITDescriptor::VecOfBitcastsToInt: {

llvm/lib/IR/Instructions.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -1879,8 +1879,7 @@ ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, ArrayRef<int> Mask,
18791879
Instruction *InsertBefore)
18801880
: Instruction(
18811881
VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
1882-
Mask.size(),
1883-
cast<VectorType>(V1->getType())->isScalable()),
1882+
Mask.size(), isa<ScalableVectorType>(V1->getType())),
18841883
ShuffleVector, OperandTraits<ShuffleVectorInst>::op_begin(this),
18851884
OperandTraits<ShuffleVectorInst>::operands(this), InsertBefore) {
18861885
assert(isValidOperands(V1, V2, Mask) &&
@@ -1895,8 +1894,7 @@ ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, ArrayRef<int> Mask,
18951894
const Twine &Name, BasicBlock *InsertAtEnd)
18961895
: Instruction(
18971896
VectorType::get(cast<VectorType>(V1->getType())->getElementType(),
1898-
Mask.size(),
1899-
cast<VectorType>(V1->getType())->isScalable()),
1897+
Mask.size(), isa<ScalableVectorType>(V1->getType())),
19001898
ShuffleVector, OperandTraits<ShuffleVectorInst>::op_begin(this),
19011899
OperandTraits<ShuffleVectorInst>::operands(this), InsertAtEnd) {
19021900
assert(isValidOperands(V1, V2, Mask) &&
@@ -1938,7 +1936,7 @@ bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2,
19381936
if (Elem != UndefMaskElem && Elem >= V1Size * 2)
19391937
return false;
19401938

1941-
if (cast<VectorType>(V1->getType())->isScalable())
1939+
if (isa<ScalableVectorType>(V1->getType()))
19421940
if ((Mask[0] != 0 && Mask[0] != UndefMaskElem) || !is_splat(Mask))
19431941
return false;
19441942

@@ -1951,10 +1949,11 @@ bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2,
19511949
if (!V1->getType()->isVectorTy() || V1->getType() != V2->getType())
19521950
return false;
19531951

1954-
// Mask must be vector of i32.
1952+
// Mask must be vector of i32, and must be the same kind of vector as the
1953+
// input vectors
19551954
auto *MaskTy = dyn_cast<VectorType>(Mask->getType());
19561955
if (!MaskTy || !MaskTy->getElementType()->isIntegerTy(32) ||
1957-
MaskTy->isScalable() != cast<VectorType>(V1->getType())->isScalable())
1956+
isa<ScalableVectorType>(MaskTy) != isa<ScalableVectorType>(V1->getType()))
19581957
return false;
19591958

19601959
// Check to see if Mask is valid.
@@ -2012,7 +2011,7 @@ void ShuffleVectorInst::setShuffleMask(ArrayRef<int> Mask) {
20122011
Constant *ShuffleVectorInst::convertShuffleMaskForBitcode(ArrayRef<int> Mask,
20132012
Type *ResultTy) {
20142013
Type *Int32Ty = Type::getInt32Ty(ResultTy->getContext());
2015-
if (cast<VectorType>(ResultTy)->isScalable()) {
2014+
if (isa<ScalableVectorType>(ResultTy)) {
20162015
assert(is_splat(Mask) && "Unexpected shuffle");
20172016
Type *VecTy = VectorType::get(Int32Ty, Mask.size(), true);
20182017
if (Mask[0] == 0)

llvm/lib/IR/Operator.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ bool GEPOperator::accumulateConstantOffset(const DataLayout &DL,
4646
continue;
4747

4848
// Scalable vectors have are multiplied by a runtime constant.
49-
if (auto *VecTy = dyn_cast<VectorType>(GTI.getIndexedType()))
50-
if (VecTy->isScalable())
51-
return false;
49+
if (isa<ScalableVectorType>(GTI.getIndexedType()))
50+
return false;
5251

5352
// Handle a struct index, which adds its field offset to the pointer.
5453
if (StructType *STy = GTI.getStructTypeOrNull()) {

llvm/lib/IR/Type.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,9 @@ StringRef StructType::getName() const {
511511
}
512512

513513
bool StructType::isValidElementType(Type *ElemTy) {
514-
if (auto *VTy = dyn_cast<VectorType>(ElemTy))
515-
return !VTy->isScalable();
516514
return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
517515
!ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() &&
518-
!ElemTy->isTokenTy();
516+
!ElemTy->isTokenTy() && !isa<ScalableVectorType>(ElemTy);
519517
}
520518

521519
bool StructType::isLayoutIdentical(StructType *Other) const {
@@ -573,11 +571,9 @@ ArrayType *ArrayType::get(Type *ElementType, uint64_t NumElements) {
573571
}
574572

575573
bool ArrayType::isValidElementType(Type *ElemTy) {
576-
if (auto *VTy = dyn_cast<VectorType>(ElemTy))
577-
return !VTy->isScalable();
578574
return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
579575
!ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() &&
580-
!ElemTy->isTokenTy();
576+
!ElemTy->isTokenTy() && !isa<ScalableVectorType>(ElemTy);
581577
}
582578

583579
//===----------------------------------------------------------------------===//

llvm/lib/IR/Verifier.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,8 @@ void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
698698
// the runtime size. If the global is a struct or an array containing
699699
// scalable vectors, that will be caught by the isValidElementType methods
700700
// in StructType or ArrayType instead.
701-
if (auto *VTy = dyn_cast<VectorType>(GV.getValueType()))
702-
Assert(!VTy->isScalable(), "Globals cannot contain scalable vectors", &GV);
701+
Assert(!isa<ScalableVectorType>(GV.getValueType()),
702+
"Globals cannot contain scalable vectors", &GV);
703703

704704
if (!GV.hasInitializer()) {
705705
visitGlobalValue(GV);

0 commit comments

Comments
 (0)