From c72546224565f8a2aa2d6467b909c9fb428aa501 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Fri, 3 Sep 2010 19:08:37 +0000 Subject: Add support for simplifying a load from a computed value to a load from a global when it is provable that they're equivalent. This fixes PR4855. llvm-svn: 112994 --- llvm/lib/Analysis/LazyValueInfo.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Analysis/LazyValueInfo.cpp') diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index b4923f9a717..e32dbc44471 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -452,14 +452,15 @@ LVILatticeVal LVIQuery::getBlockValue(BasicBlock *BB) { // If this is a pointer, and there's a load from that pointer in this BB, // then we know that the pointer can't be NULL. + bool NotNull = false; if (Val->getType()->isPointerTy()) { - const PointerType *PTy = cast(Val->getType()); for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();BI != BE;++BI){ LoadInst *L = dyn_cast(BI); if (L && L->getPointerAddressSpace() == 0 && L->getPointerOperand()->getUnderlyingObject() == Val->getUnderlyingObject()) { - return LVILatticeVal::getNot(ConstantPointerNull::get(PTy)); + NotNull = true; + break; } } } @@ -475,11 +476,19 @@ LVILatticeVal LVIQuery::getBlockValue(BasicBlock *BB) { if (Result.isOverdefined()) { DEBUG(dbgs() << " compute BB '" << BB->getName() << "' - overdefined because of pred.\n"); + // If we previously determined that this is a pointer that can't be null + // then return that rather than giving up entirely. + if (NotNull) { + const PointerType *PTy = cast(Val->getType()); + Result = LVILatticeVal::getNot(ConstantPointerNull::get(PTy)); + } + return Result; } ++NumPreds; } + // If this is the entry block, we must be asking about an argument. The // value is overdefined. if (NumPreds == 0 && BB == &BB->getParent()->front()) { -- cgit v1.2.3