* Add better caching of data to avoid silly recusions
authorChris Lattner <sabre@nondot.org>
Thu, 8 Nov 2001 22:06:31 +0000 (22:06 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 8 Nov 2001 22:06:31 +0000 (22:06 +0000)
* Only check to see if uses of instructions can be converted for expressions... so we don't look at all of the uses of a constant.  This was making the code unnecessarily conservative

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

lib/Transforms/ExprTypeConvert.cpp

index 3b0f3d2707443d2eb08195ea61f88b4d6c7ae79e..f6fdb7e1872530871a9ac6aa20f7231731e9b07b 100644 (file)
@@ -77,9 +77,11 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
   // have this value converted.  This makes use of the map to avoid infinite
   // recursion.
   //
-  for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I)
-    if (!OperandConvertableToType(*I, V, Ty, CTMap))
-      return false;
+  if (isa<Instruction>(V)) {
+    for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I)
+      if (!OperandConvertableToType(*I, V, Ty, CTMap))
+        return false;
+  }
 
   Instruction *I = dyn_cast<Instruction>(V);
   if (I == 0) {
@@ -336,6 +338,8 @@ bool RetValConvertableToType(Value *V, const Type *Ty,
   if (I != ConvertedTypes.end()) return I->second == Ty;
   ConvertedTypes[V] = Ty;
 
+  assert(isa<Instruction>(V) && "Can't convert ret val of non instruction");
+
   // It is safe to convert the specified value to the specified type IFF all of
   // the uses of the value can be converted to accept the new typed value.
   //
@@ -389,6 +393,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
     }
     // FALLTHROUGH
   case Instruction::Sub: {
+    CTMap[I] = Ty;
     Value *OtherOp = I->getOperand((V == I->getOperand(0)) ? 1 : 0);
     return RetValConvertableToType(I, Ty, CTMap) &&
            ExpressionConvertableToType(OtherOp, Ty, CTMap);
@@ -403,6 +408,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
     // FALL THROUGH
   case Instruction::Shl:
     assert(I->getOperand(0) == V);
+    CTMap[I] = Ty;
     return RetValConvertableToType(I, Ty, CTMap);
 
   case Instruction::Load:
@@ -427,6 +433,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
           if (TD.getTypeSize(Ty) != TD.getTypeSize(LI->getType()))
             return false;
 
+          CTMap[LI] = Ty;
           return RetValConvertableToType(LI, Ty, CTMap);
         }
         return false;
@@ -435,6 +442,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
       if (TD.getTypeSize(PVTy) != TD.getTypeSize(LI->getType()))
         return false;
 
+      CTMap[LI] = PVTy;
       return RetValConvertableToType(LI, PVTy, CTMap);
     }
     return false;
@@ -465,6 +473,7 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
   }
 
   case Instruction::PHINode: {
+    CTMap[I] = Ty;
     PHINode *PN = cast<PHINode>(I);
     for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i)
       if (!ExpressionConvertableToType(PN->getIncomingValue(i), Ty, CTMap))