Permit the IntPtrTy argument to isEliminableCastPair to be null,
authorDan Gohman <gohman@apple.com>
Tue, 21 Jul 2009 23:19:40 +0000 (23:19 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 21 Jul 2009 23:19:40 +0000 (23:19 +0000)
to help support use when TargetData is not available.

llvm-svn: 76675

llvm/include/llvm/InstrTypes.h
llvm/lib/VMCore/Instructions.cpp

index 1ee2a4b..c3c48af 100644 (file)
@@ -479,7 +479,7 @@ public:
     const Type *SrcTy, ///< SrcTy of 1st cast
     const Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
     const Type *DstTy, ///< DstTy of 2nd cast
-    const Type *IntPtrTy ///< Integer type corresponding to Ptr types
+    const Type *IntPtrTy ///< Integer type corresponding to Ptr types, or null
   );
 
   /// @brief Return the opcode of this CastInst
index e04d54c..5e5ce64 100644 (file)
@@ -1890,6 +1890,8 @@ unsigned CastInst::isEliminableCastPair(
       return 0;
     case 7: { 
       // ptrtoint, inttoptr -> bitcast (ptr -> ptr) if int size is >= ptr size
+      if (!IntPtrTy)
+        return 0;
       unsigned PtrSize = IntPtrTy->getScalarSizeInBits();
       unsigned MidSize = MidTy->getScalarSizeInBits();
       if (MidSize >= PtrSize)
@@ -1929,6 +1931,8 @@ unsigned CastInst::isEliminableCastPair(
       return 0;
     case 13: {
       // inttoptr, ptrtoint -> bitcast if SrcSize<=PtrSize and SrcSize==DstSize
+      if (!IntPtrTy)
+        return 0;
       unsigned PtrSize = IntPtrTy->getScalarSizeInBits();
       unsigned SrcSize = SrcTy->getScalarSizeInBits();
       unsigned DstSize = DstTy->getScalarSizeInBits();