Re-enable 91381 with fixes.
[oota-llvm.git] / lib / Analysis / ValueTracking.cpp
index 3e6af58aa935a6e9803ff0037052cc3862a64069..acd3119abea8c1ee81c0b886a337365a41be6175 100644 (file)
@@ -659,7 +659,7 @@ unsigned llvm::ComputeNumSignBits(Value *V, const TargetData *TD,
   switch (Operator::getOpcode(V)) {
   default: break;
   case Instruction::SExt:
-    Tmp = TyBits-cast<IntegerType>(U->getOperand(0)->getType())->getBitWidth();
+    Tmp = TyBits - U->getOperand(0)->getType()->getScalarSizeInBits();
     return ComputeNumSignBits(U->getOperand(0), TD, Depth+1) + Tmp;
     
   case Instruction::AShr:
@@ -1028,9 +1028,11 @@ static Value *GetLinearExpression(Value *V, APInt &Scale, APInt &Offset,
 const Value *llvm::DecomposeGEPExpression(const Value *V, int64_t &BaseOffs,
                  SmallVectorImpl<std::pair<const Value*, int64_t> > &VarIndices,
                                           const TargetData *TD) {
-  // FIXME: Should limit depth like getUnderlyingObject?
+  // Limit recursion depth to limit compile time in crazy cases.
+  unsigned MaxLookup = 6;
+  
   BaseOffs = 0;
-  while (1) {
+  do {
     // See if this is a bitcast or GEP.
     const Operator *Op = dyn_cast<Operator>(V);
     if (Op == 0) {
@@ -1128,7 +1130,10 @@ const Value *llvm::DecomposeGEPExpression(const Value *V, int64_t &BaseOffs,
     
     // Analyze the base pointer next.
     V = GEPOp->getOperand(0);
-  }
+  } while (--MaxLookup);
+  
+  // If the chain of expressions is too deep, just return early.
+  return V;
 }
 
 
@@ -1364,11 +1369,6 @@ bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset,
                                  StopAtNul);
   }
   
-  if (MDString *MDStr = dyn_cast<MDString>(V)) {
-    Str = MDStr->getString();
-    return true;
-  }
-
   // The GEP instruction, constant or instruction, must reference a global
   // variable that is a constant and is initialized. The referenced constant
   // initializer is the array that we'll use for optimization.