]> granicus.if.org Git - llvm/commitdiff
IR: Change the Type::get{Array,Vector,Pointer}ElementType() functions to perform...
authorPeter Collingbourne <peter@pcc.me.uk>
Sun, 13 Nov 2016 06:58:45 +0000 (06:58 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Sun, 13 Nov 2016 06:58:45 +0000 (06:58 +0000)
Previously we were only asserting that the type was a sequential type.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286749 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Type.h
lib/IR/Instructions.cpp

index 52ef5605f7d139e150df2bbcd78edec7c561f21a..4e2ef5301f5efd3cbc0ff1bf3f2dfc9f5ffca79c 100644 (file)
@@ -344,12 +344,21 @@ public:
   }
 
   inline uint64_t getArrayNumElements() const;
-  Type *getArrayElementType() const { return getSequentialElementType(); }
+  Type *getArrayElementType() const {
+    assert(getTypeID() == ArrayTyID);
+    return ContainedTys[0];
+  }
 
   inline unsigned getVectorNumElements() const;
-  Type *getVectorElementType() const { return getSequentialElementType(); }
+  Type *getVectorElementType() const {
+    assert(getTypeID() == VectorTyID);
+    return ContainedTys[0];
+  }
 
-  Type *getPointerElementType() const { return getSequentialElementType(); }
+  Type *getPointerElementType() const {
+    assert(getTypeID() == PointerTyID);
+    return ContainedTys[0];
+  }
 
   /// Get the address space of this pointer or pointer vector type.
   inline unsigned getPointerAddressSpace() const;
index dcd0feb43cb6480712b27ab40d12e08c1b91760f..693879be181f0436e555cb7728b8788f7af07f30 100644 (file)
@@ -2550,7 +2550,8 @@ unsigned CastInst::isEliminableCastPair(
     case 14:
       // bitcast, addrspacecast -> addrspacecast if the element type of
       // bitcast's source is the same as that of addrspacecast's destination.
-      if (SrcTy->getPointerElementType() == DstTy->getPointerElementType())
+      if (SrcTy->getScalarType()->getPointerElementType() ==
+          DstTy->getScalarType()->getPointerElementType())
         return Instruction::AddrSpaceCast;
       return 0;