From da34de159984fd3dcc7d9665fcd7fe9f651a1b61 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Tue, 24 Aug 2010 20:47:29 +0000 Subject: Add support for inferring that a load from a pointer implies that it is not null. llvm-svn: 111959 --- llvm/lib/Analysis/LazyValueInfo.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Analysis/LazyValueInfo.cpp') diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index e8cc69de551..3ecaeed9192 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -367,6 +367,7 @@ namespace { /// NewBlocks - This is a mapping of the new BasicBlocks which have been /// added to cache but that are not in sorted order. DenseSet NewBlockInfo; + public: LVIQuery(Value *V, LazyValueInfoCache &P, @@ -448,12 +449,24 @@ LVILatticeVal LVIQuery::getBlockValue(BasicBlock *BB) { BBLV.markOverdefined(); Cache[BB] = BBLV; - // If V is live into BB, see if our predecessors know anything about it. Instruction *BBI = dyn_cast(Val); if (BBI == 0 || BBI->getParent() != BB) { LVILatticeVal Result; // Start Undefined. - unsigned NumPreds = 0; + // 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. + if (Val->getType()->isPointerTy()) { + const PointerType *PTy = cast(Val->getType()); + for (Value::use_iterator UI = Val->use_begin(), UE = Val->use_end(); + UI != UE; ++UI) { + LoadInst *L = dyn_cast(*UI); + if (L && L->getParent() == BB) { + return LVILatticeVal::getNot(ConstantPointerNull::get(PTy)); + } + } + } + + unsigned NumPreds = 0; // Loop over all of our predecessors, merging what we know from them into // result. for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { @@ -694,8 +707,8 @@ LVILatticeVal LazyValueInfoCache::getValueInBlock(Value *V, BasicBlock *BB) { << BB->getName() << "'\n"); LVILatticeVal Result = LVIQuery(V, *this, - ValueCache[LVIValueHandle(V, this)], - OverDefinedCache).getBlockValue(BB); + ValueCache[LVIValueHandle(V, this)], + OverDefinedCache).getBlockValue(BB); DEBUG(dbgs() << " Result = " << Result << "\n"); return Result; -- cgit v1.2.3