Limit the number of times we're willing to chase pointers. Removes an O(n^2)

problem from instcombine.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69151 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky 2009-04-15 06:23:41 +00:00
parent 37a4d8dbbb
commit 300e36503c

View File

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