[llvm] 1e04923 - [MachineValueType] Don't allow MVT::getVectorNumElements() to be called for scalable vectors.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 13 09:22:27 PST 2022


Author: Craig Topper
Date: 2022-01-13T09:16:25-08:00
New Revision: 1e04923d21f8e2a3557690340ac7e7936dab20e5

URL: https://github.com/llvm/llvm-project/commit/1e04923d21f8e2a3557690340ac7e7936dab20e5
DIFF: https://github.com/llvm/llvm-project/commit/1e04923d21f8e2a3557690340ac7e7936dab20e5.diff

LOG: [MachineValueType] Don't allow MVT::getVectorNumElements() to be called for scalable vectors.

Migrate the one caller that failed lit tests to use
MVT::getVectorMinNumElements directly.

Added: 
    

Modified: 
    llvm/include/llvm/Support/MachineValueType.h
    llvm/lib/Support/LowLevelType.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/MachineValueType.h b/llvm/include/llvm/Support/MachineValueType.h
index ce10a4c58dfe8..643c2d8ce9817 100644
--- a/llvm/include/llvm/Support/MachineValueType.h
+++ b/llvm/include/llvm/Support/MachineValueType.h
@@ -848,7 +848,11 @@ namespace llvm {
     }
 
     unsigned getVectorNumElements() const {
-      // TODO: Check that this isn't a scalable vector.
+      if (isScalableVector())
+        llvm::reportInvalidSizeRequest(
+            "Possible incorrect use of MVT::getVectorNumElements() for "
+            "scalable vector. Scalable flag may be dropped, use "
+            "MVT::getVectorElementCount() instead");
       return getVectorMinNumElements();
     }
 

diff  --git a/llvm/lib/Support/LowLevelType.cpp b/llvm/lib/Support/LowLevelType.cpp
index ecf557997ad1a..0282cd9bd79ed 100644
--- a/llvm/lib/Support/LowLevelType.cpp
+++ b/llvm/lib/Support/LowLevelType.cpp
@@ -17,7 +17,7 @@ using namespace llvm;
 
 LLT::LLT(MVT VT) {
   if (VT.isVector()) {
-    bool asVector = VT.getVectorNumElements() > 1;
+    bool asVector = VT.getVectorMinNumElements() > 1;
     init(/*IsPointer=*/false, asVector, /*IsScalar=*/!asVector,
          VT.getVectorElementCount(), VT.getVectorElementType().getSizeInBits(),
          /*AddressSpace=*/0);


        


More information about the llvm-commits mailing list