diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2011-01-15 09:16:12 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2011-01-15 09:16:12 +0000 |
commit | 367f98f000841d03d9796c04b9d51a117f1c2dbf (patch) | |
tree | 8b1f96a7a0dae307ac2b966cb7d78ef2f1aeeba0 /llvm/lib/Analysis/LazyValueInfo.cpp | |
parent | facb7d0adefc5c3baacb6618256a6d7737104cb6 (diff) | |
download | bcm5719-llvm-367f98f000841d03d9796c04b9d51a117f1c2dbf.tar.gz bcm5719-llvm-367f98f000841d03d9796c04b9d51a117f1c2dbf.zip |
Teach LazyValueInfo that allocas aren't NULL. Over all of llvm-test, this saves
half a million non-local queries, each of which would otherwise have triggered a
linear scan over a basic block.
Also fix a fixme for memory intrinsics which dereference pointers. With this,
we prove that a pointer is non-null because it was dereferenced by an intrinsic
112 times in llvm-test.
llvm-svn: 123533
Diffstat (limited to 'llvm/lib/Analysis/LazyValueInfo.cpp')
-rw-r--r-- | llvm/lib/Analysis/LazyValueInfo.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 9be106b8575..9e7da6ce2de 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -17,6 +17,7 @@ #include "llvm/Analysis/ValueTracking.h" #include "llvm/Constants.h" #include "llvm/Instructions.h" +#include "llvm/IntrinsicInst.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Target/TargetData.h" #include "llvm/Support/CFG.h" @@ -544,6 +545,11 @@ bool LazyValueInfoCache::solveBlockValue(Value *Val, BasicBlock *BB) { return ODCacheUpdater.markResult(solveBlockValuePHINode(BBLV, PN, BB)); } + if (AllocaInst *AI = dyn_cast<AllocaInst>(BBI)) { + BBLV = LVILatticeVal::getNot(ConstantPointerNull::get(AI->getType())); + return ODCacheUpdater.markResult(true); + } + // We can only analyze the definitions of certain classes of instructions // (integral binops and casts at the moment), so bail if this isn't one. LVILatticeVal Result; @@ -580,7 +586,19 @@ static bool InstructionDereferencesPointer(Instruction *I, Value *Ptr) { GetUnderlyingObject(S->getPointerOperand()) == GetUnderlyingObject(Ptr); } - // FIXME: llvm.memset, etc. + if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(I)) { + if (MI->isVolatile()) return false; + if (MI->getAddressSpace() != 0) return false; + + // FIXME: check whether it has a valuerange that excludes zero? + ConstantInt *Len = dyn_cast<ConstantInt>(MI->getLength()); + if (!Len || Len->isZero()) return false; + + if (MI->getRawDest() == Ptr || MI->getDest() == Ptr) + return true; + if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(MI)) + return MTI->getRawSource() == Ptr || MTI->getSource() == Ptr; + } return false; } @@ -592,10 +610,14 @@ bool LazyValueInfoCache::solveBlockValueNonLocal(LVILatticeVal &BBLV, // then we know that the pointer can't be NULL. bool NotNull = false; if (Val->getType()->isPointerTy()) { - for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();BI != BE;++BI){ - if (InstructionDereferencesPointer(BI, Val)) { - NotNull = true; - break; + if (isa<AllocaInst>(Val)) { + NotNull = true; + } else { + for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();BI != BE;++BI){ + if (InstructionDereferencesPointer(BI, Val)) { + NotNull = true; + break; + } } } } |