diff options
author | Chris Lattner <sabre@nondot.org> | 2008-11-30 01:39:32 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-11-30 01:39:32 +0000 |
commit | 237a8287454389a5b940e18c1efb2201fc443208 (patch) | |
tree | d66f515f18d652d4a41966cf44252a2c9cfe5e09 /lib/Analysis/MemoryDependenceAnalysis.cpp | |
parent | 73ec3cdd7140aee6d2b9ac32bc2298254ff48c97 (diff) |
Fix a fixme by making memdep's handling of allocations more logical.
If we see that a load depends on the allocation of its memory with no
intervening stores, we now return a 'None' depedency instead of "Normal".
This tweaks GVN to do its optimization with the new result.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60267 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/MemoryDependenceAnalysis.cpp')
-rw-r--r-- | lib/Analysis/MemoryDependenceAnalysis.cpp | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp index 94a3d1ba78..e135f1160e 100644 --- a/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -159,29 +159,19 @@ getDependencyFromInternal(Instruction *QueryInst, BasicBlock::iterator ScanIt, continue; return DepResultTy(Inst, Normal); } - - // FIXME: This claims that an access depends on the allocation. This may - // make sense, but is dubious at best. It would be better to fix GVN to - // handle a 'None' Query. + + // If this is an allocation, and if we know that the accessed pointer is to + // the allocation, return None. This means that there is no dependence and + // the access can be optimized based on that. For example, a load could + // turn into undef. if (AllocationInst *AI = dyn_cast<AllocationInst>(Inst)) { - Value *Pointer = AI; - uint64_t PointerSize; - if (ConstantInt *C = dyn_cast<ConstantInt>(AI->getArraySize())) - // Use ABI size (size between elements), not store size (size of one - // element without padding). - PointerSize = C->getZExtValue() * - TD.getABITypeSize(AI->getAllocatedType()); - else - PointerSize = ~0UL; + Value *AccessPtr = MemPtr->getUnderlyingObject(); - AliasAnalysis::AliasResult R = - AA.alias(Pointer, PointerSize, MemPtr, MemSize); - - if (R == AliasAnalysis::NoAlias) - continue; - return DepResultTy(Inst, Normal); + if (AccessPtr == AI || + AA.alias(AI, 1, AccessPtr, 1) == AliasAnalysis::MustAlias) + return DepResultTy(0, None); + continue; } - // See if this instruction mod/ref's the pointer. AliasAnalysis::ModRefResult MRR = AA.getModRefInfo(Inst, MemPtr, MemSize); |