[llvm] 8bec33c - [SVE] Remove VectorType::getBitWidth()
Christopher Tetreault via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 21 13:34:02 PDT 2020
Author: Christopher Tetreault
Date: 2020-04-21T13:33:46-07:00
New Revision: 8bec33c096bd71bbace60c4371cde88fd48ae651
URL: https://github.com/llvm/llvm-project/commit/8bec33c096bd71bbace60c4371cde88fd48ae651
DIFF: https://github.com/llvm/llvm-project/commit/8bec33c096bd71bbace60c4371cde88fd48ae651.diff
LOG: [SVE] Remove VectorType::getBitWidth()
Summary:
* VectorType::getBitWidth() is just an unsafe version of
getPrimitiveSizeInBits() that assumes all vectors are fixed width.
Reviewers: efriedma, sdesmalen, huntergr, craig.topper
Reviewed By: efriedma
Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77833
Added:
Modified:
llvm/include/llvm/IR/DerivedTypes.h
llvm/lib/IR/Type.cpp
llvm/unittests/AsmParser/AsmParserTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/DerivedTypes.h b/llvm/include/llvm/IR/DerivedTypes.h
index 186430754303..306d388cb8a7 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -519,12 +519,6 @@ class VectorType : public Type {
return Scalable;
}
- /// Return the minimum number of bits in the Vector type.
- /// Returns zero when the vector is a vector of pointers.
- unsigned getBitWidth() const {
- return getNumElements() * getElementType()->getPrimitiveSizeInBits();
- }
-
/// Methods for support type inquiry through isa, cast, and dyn_cast.
static bool classof(const Type *T) {
return T->getTypeID() == VectorTyID;
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 17ca43cbbccb..e8c693aedf64 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -68,20 +68,20 @@ bool Type::canLosslesslyBitCastTo(Type *Ty) const {
return false;
// Vector -> Vector conversions are always lossless if the two vector types
- // have the same size, otherwise not. Also, 64-bit vector types can be
- // converted to x86mmx.
- if (auto *thisPTy = dyn_cast<VectorType>(this)) {
- if (auto *thatPTy = dyn_cast<VectorType>(Ty))
- return thisPTy->getBitWidth() == thatPTy->getBitWidth();
- if (Ty->getTypeID() == Type::X86_MMXTyID &&
- thisPTy->getBitWidth() == 64)
- return true;
- }
-
- if (this->getTypeID() == Type::X86_MMXTyID)
- if (auto *thatPTy = dyn_cast<VectorType>(Ty))
- if (thatPTy->getBitWidth() == 64)
- return true;
+ // have the same size, otherwise not.
+ if (isa<VectorType>(this) && isa<VectorType>(Ty))
+ return getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits();
+
+ // 64-bit fixed width vector types can be losslessly converted to x86mmx.
+ if (((isa<VectorType>(this) &&
+ !cast<VectorType>(this)->getElementCount().Scalable) &&
+ Ty->isX86_MMXTy()) &&
+ getPrimitiveSizeInBits().getFixedSize() == 64)
+ return true;
+ if ((isX86_MMXTy() && (isa<VectorType>(Ty) &&
+ !cast<VectorType>(Ty)->getElementCount().Scalable)) &&
+ Ty->getPrimitiveSizeInBits().getFixedSize() == 64)
+ return true;
// At this point we have only various mismatches of the first class types
// remaining and ptr->ptr. Just select the lossless conversions. Everything
@@ -125,7 +125,10 @@ TypeSize Type::getPrimitiveSizeInBits() const {
return TypeSize::Fixed(cast<IntegerType>(this)->getBitWidth());
case Type::VectorTyID: {
const VectorType *VTy = cast<VectorType>(this);
- return TypeSize(VTy->getBitWidth(), VTy->isScalable());
+ ElementCount EC = VTy->getElementCount();
+ TypeSize ETS = VTy->getElementType()->getPrimitiveSizeInBits();
+ assert(!ETS.isScalable() && "Vector type should have fixed-width elements");
+ return {ETS.getFixedSize() * EC.Min, EC.Scalable};
}
default: return TypeSize::Fixed(0);
}
diff --git a/llvm/unittests/AsmParser/AsmParserTest.cpp b/llvm/unittests/AsmParser/AsmParserTest.cpp
index d5f734d390af..198191bf435f 100644
--- a/llvm/unittests/AsmParser/AsmParserTest.cpp
+++ b/llvm/unittests/AsmParser/AsmParserTest.cpp
@@ -232,7 +232,7 @@ TEST(AsmParserTest, TypeWithSlotMappingParsing) {
// Check the details of the vector.
VectorType *VT = cast<VectorType>(Ty);
ASSERT_TRUE(VT->getNumElements() == 5);
- ASSERT_TRUE(VT->getBitWidth() == 160);
+ ASSERT_TRUE(VT->getPrimitiveSizeInBits().getFixedSize() == 160);
Ty = VT->getElementType();
ASSERT_TRUE(Ty->isIntegerTy());
ASSERT_TRUE(Ty->getPrimitiveSizeInBits() == 32);
@@ -364,7 +364,7 @@ TEST(AsmParserTest, TypeAtBeginningWithSlotMappingParsing) {
// Check the details of the vector.
VectorType *VT = cast<VectorType>(Ty);
ASSERT_TRUE(VT->getNumElements() == 5);
- ASSERT_TRUE(VT->getBitWidth() == 160);
+ ASSERT_TRUE(VT->getPrimitiveSizeInBits().getFixedSize() == 160);
Ty = VT->getElementType();
ASSERT_TRUE(Ty->isIntegerTy());
ASSERT_TRUE(Ty->getPrimitiveSizeInBits() == 32);
More information about the llvm-commits
mailing list