Limit the number of times we're willing to chase pointers. Removes an O(n^2)
authorNick Lewycky <nicholas@mxc.ca>
Wed, 15 Apr 2009 06:23:41 +0000 (06:23 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Wed, 15 Apr 2009 06:23:41 +0000 (06:23 +0000)
problem from instcombine.

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

lib/VMCore/Value.cpp

index 499b936e29ceccd88110bd8c81a2acd8f02b5f63..af3f4e70784b7df9f8c60cd7ffc441410e09bb63 100644 (file)
@@ -365,6 +365,7 @@ Value *Value::getUnderlyingObject() {
   if (!isa<PointerType>(getType()))
     return this;
   Value *V = this;
+  unsigned MaxLookup = 6;
   do {
     if (Instruction *I = dyn_cast<Instruction>(V)) {
       if (!isa<BitCastInst>(I) && !isa<GetElementPtrInst>(I))
@@ -379,7 +380,8 @@ Value *Value::getUnderlyingObject() {
       return V;
     }
     assert(isa<PointerType>(V->getType()) && "Unexpected operand type!");
-  } while (1);
+  } while (--MaxLookup);
+  return V;
 }
 
 /// DoPHITranslation - If this value is a PHI node with CurBB as its parent,