Fix a few bugs. Fix pessimization handling sized arrays
authorChris Lattner <sabre@nondot.org>
Wed, 5 Dec 2001 19:39:15 +0000 (19:39 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 5 Dec 2001 19:39:15 +0000 (19:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1422 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/ExprTypeConvert.cpp

index f71687abe8077d731a7983b16c2d50277664fefa..7226be3b95a22f40c9b5f97aa9a78038790ffa7d 100644 (file)
@@ -317,6 +317,8 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
 
 
 Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
+  if (V->getType() == Ty) return V;  // Already where we need to be?
+
   ValueMapCache::ExprMapTy::iterator VMCI = VMC.ExprMap.find(V);
   if (VMCI != VMC.ExprMap.end()) {
     assert(VMCI->second->getType() == Ty);
@@ -623,17 +625,17 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
       return ExpressionConvertableToType(I->getOperand(1), PointerType::get(Ty),
                                          CTMap);
     } else if (const PointerType *PT = dyn_cast<PointerType>(Ty)) {
-      if (isa<ArrayType>(PT->getElementType()))
-        return false;  // Avoid getDataSize on unsized array type!
+      const Type *ElTy = PT->getElementType();
+      if (ArrayType *AT = dyn_cast<ArrayType>(ElTy))
+        ElTy = AT->getElementType(); // Avoid getDataSize on unsized array type!
       assert(V == I->getOperand(1));
 
       // Must move the same amount of data...
-      if (TD.getTypeSize(PT->getElementType()) != 
-          TD.getTypeSize(I->getOperand(0)->getType())) return false;
+      if (TD.getTypeSize(ElTy) != TD.getTypeSize(I->getOperand(0)->getType()))
+        return false;
 
       // Can convert store if the incoming value is convertable...
-      return ExpressionConvertableToType(I->getOperand(0), PT->getElementType(),
-                                         CTMap);
+      return ExpressionConvertableToType(I->getOperand(0), ElTy, CTMap);
     }
     return false;
   }
@@ -794,7 +796,13 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
       Res->setOperand(1, ConvertExpressionToType(I->getOperand(1), NewPT, VMC));
     } else {                           // Replace the source pointer
       const Type *ValTy = cast<PointerType>(NewTy)->getElementType();
-      Res = new StoreInst(Constant::getNullConstant(ValTy), NewVal);
+      vector<Value*> Indices;
+      while (ArrayType *AT = dyn_cast<ArrayType>(ValTy)) {
+        Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
+        ValTy = AT->getElementType();
+      }
+
+      Res = new StoreInst(Constant::getNullConstant(ValTy), NewVal, Indices);
       VMC.ExprMap[I] = Res;
       Res->setOperand(0, ConvertExpressionToType(I->getOperand(0), ValTy, VMC));
     }