[llvm] baab797 - [ValueTypes] Assert if changeVectorElementType is called on a simple type with an extended element type.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 19 17:35:39 PST 2021


Author: Craig Topper
Date: 2021-02-19T17:30:46-08:00
New Revision: baab7978787d64df25ab073bb7e0ec92b5608797

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

LOG: [ValueTypes] Assert if changeVectorElementType is called on a simple type with an extended element type.

Previously we would use the extended implementation, but
the extended implementation requires the vector type to be extended
so that we can access the LLVMContext. In theory we could
detect this case and use the context from the element type instead,
but since I know of no cases hitting this in practice today
I've done the simplest thing.

Also add asserts to several extended EVT functions that assume
LLVMTy is non-null.

Follow from discussion in D97036

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D97070

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/ValueTypes.h
    llvm/lib/CodeGen/ValueTypes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/ValueTypes.h b/llvm/include/llvm/CodeGen/ValueTypes.h
index 888b83d6f736..ccdaab5ed96d 100644
--- a/llvm/include/llvm/CodeGen/ValueTypes.h
+++ b/llvm/include/llvm/CodeGen/ValueTypes.h
@@ -100,8 +100,11 @@ namespace llvm {
     /// Return a VT for a vector type whose attributes match ourselves
     /// with the exception of the element type that is chosen by the caller.
     EVT changeVectorElementType(EVT EltVT) const {
-      if (isSimple() && EltVT.isSimple())
+      if (isSimple()) {
+        assert(EltVT.isSimple() &&
+               "Can't change simple vector VT to have extended element VT");
         return getSimpleVT().changeVectorElementType(EltVT.getSimpleVT());
+      }
       return changeExtendedVectorElementType(EltVT);
     }
 

diff  --git a/llvm/lib/CodeGen/ValueTypes.cpp b/llvm/lib/CodeGen/ValueTypes.cpp
index 7e4c4b1c634e..7f38420b8370 100644
--- a/llvm/lib/CodeGen/ValueTypes.cpp
+++ b/llvm/lib/CodeGen/ValueTypes.cpp
@@ -15,11 +15,13 @@
 using namespace llvm;
 
 EVT EVT::changeExtendedTypeToInteger() const {
+  assert(isExtended() && "Type is not extended!");
   LLVMContext &Context = LLVMTy->getContext();
   return getIntegerVT(Context, getSizeInBits());
 }
 
 EVT EVT::changeExtendedVectorElementTypeToInteger() const {
+  assert(isExtended() && "Type is not extended!");
   LLVMContext &Context = LLVMTy->getContext();
   EVT IntTy = getIntegerVT(Context, getScalarSizeInBits());
   return getVectorVT(Context, IntTy, getVectorNumElements(),
@@ -27,6 +29,7 @@ EVT EVT::changeExtendedVectorElementTypeToInteger() const {
 }
 
 EVT EVT::changeExtendedVectorElementType(EVT EltVT) const {
+  assert(isExtended() && "Type is not extended!");
   LLVMContext &Context = LLVMTy->getContext();
   return getVectorVT(Context, EltVT, getVectorElementCount());
 }


        


More information about the llvm-commits mailing list