summaryrefslogtreecommitdiff
path: root/lib/Analysis/LazyValueInfo.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2010-08-24 20:47:29 +0000
committerOwen Anderson <resistor@mac.com>2010-08-24 20:47:29 +0000
commitc8ef750605385b3704c0e310b91a0e042cac5781 (patch)
treea01d023bacf9d909fe44ade9237009a3dc7a192e /lib/Analysis/LazyValueInfo.cpp
parentc1840b3da25222680b51f853697a871fedda51d5 (diff)
downloadllvm-c8ef750605385b3704c0e310b91a0e042cac5781.tar.gz
llvm-c8ef750605385b3704c0e310b91a0e042cac5781.tar.bz2
llvm-c8ef750605385b3704c0e310b91a0e042cac5781.tar.xz
Add support for inferring that a load from a pointer implies that it is not null.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111959 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/LazyValueInfo.cpp')
-rw-r--r--lib/Analysis/LazyValueInfo.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/Analysis/LazyValueInfo.cpp b/lib/Analysis/LazyValueInfo.cpp
index e8cc69de55..3ecaeed919 100644
--- a/lib/Analysis/LazyValueInfo.cpp
+++ b/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<BasicBlock*> 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<Instruction>(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<PointerType>(Val->getType());
+ for (Value::use_iterator UI = Val->use_begin(), UE = Val->use_end();
+ UI != UE; ++UI) {
+ LoadInst *L = dyn_cast<LoadInst>(*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;