[llvm-commits] [llvm] r119927 - in /llvm/trunk: include/llvm/Analysis/MemoryDependenceAnalysis.h lib/Analysis/MemoryDependenceAnalysis.cpp lib/Transforms/Scalar/DeadStoreElimination.cpp test/Transforms/DeadStoreElimination/simple.ll
Chris Lattner
sabre at nondot.org
Sat Nov 20 23:34:32 PST 2010
Author: lattner
Date: Sun Nov 21 01:34:32 2010
New Revision: 119927
URL: http://llvm.org/viewvc/llvm-project?rev=119927&view=rev
Log:
implement PR8576, deleting dead stores with intervening may-alias stores.
Modified:
llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h
llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll
Modified: llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h?rev=119927&r1=119926&r2=119927&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/MemoryDependenceAnalysis.h Sun Nov 21 01:34:32 2010
@@ -335,11 +335,19 @@
/// critical edges.
void invalidateCachedPredecessors();
- private:
+ /// getPointerDependencyFrom - Return the instruction on which a memory
+ /// location depends. If isLoad is true, this routine ignores may-aliases
+ /// with read-only operations. If isLoad is false, this routine ignores
+ /// may-aliases with reads from read-only locations.
+ ///
+ /// Note that this is an uncached query, and thus may be inefficient.
+ ///
MemDepResult getPointerDependencyFrom(const AliasAnalysis::Location &Loc,
bool isLoad,
BasicBlock::iterator ScanIt,
BasicBlock *BB);
+
+ private:
MemDepResult getCallSiteDependencyFrom(CallSite C, bool isReadOnlyCall,
BasicBlock::iterator ScanIt,
BasicBlock *BB);
Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=119927&r1=119926&r2=119927&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Sun Nov 21 01:34:32 2010
@@ -409,9 +409,9 @@
if (MemLoc.Ptr) {
// If we can do a pointer scan, make it happen.
bool isLoad = !(MR & AliasAnalysis::Mod);
- if (IntrinsicInst *II = dyn_cast<MemoryUseIntrinsic>(QueryInst)) {
+ if (IntrinsicInst *II = dyn_cast<MemoryUseIntrinsic>(QueryInst))
isLoad |= II->getIntrinsicID() == Intrinsic::lifetime_end;
- }
+
LocalCache = getPointerDependencyFrom(MemLoc, isLoad, ScanPos,
QueryParent);
} else if (isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst)) {
Modified: llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp?rev=119927&r1=119926&r2=119927&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp Sun Nov 21 01:34:32 2010
@@ -217,9 +217,28 @@
continue;
}
- // If not a definite must-alias dependency, ignore it.
- if (!InstDep.isDef())
- continue;
+ if (!InstDep.isDef()) {
+ // If this is a may-aliased store that is clobbering the store value, we
+ // can keep searching past it for another must-aliased pointer that stores
+ // to the same location. For example, in:
+ // store -> P
+ // store -> Q
+ // store -> P
+ // we can remove the first store to P even though we don't know if P and Q
+ // alias.
+ if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
+ AliasAnalysis::Location Loc =
+ getAnalysis<AliasAnalysis>().getLocation(SI);
+ while (InstDep.isClobber() && isa<StoreInst>(InstDep.getInst()) &&
+ InstDep.getInst() != &BB.front())
+ InstDep = MD.getPointerDependencyFrom(Loc, false, InstDep.getInst(),
+ &BB);
+ }
+
+ // If not a definite must-alias dependency, ignore it.
+ if (!InstDep.isDef())
+ continue;
+ }
// If this is a store-store dependence, then the previous store is dead so
// long as this store is at least as big as it.
Modified: llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll?rev=119927&r1=119926&r2=119927&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll (original)
+++ llvm/trunk/test/Transforms/DeadStoreElimination/simple.ll Sun Nov 21 01:34:32 2010
@@ -11,3 +11,12 @@
; CHECK-NEXT: ret void
}
+; PR8576 - Should delete store of 10 even though p/q are may aliases.
+define void @test2(i32 *%p, i32 *%q) {
+ store i32 10, i32* %p, align 4
+ store i32 20, i32* %q, align 4
+ store i32 30, i32* %p, align 4
+ ret void
+; CHECK: @test2
+; CHECK-NEXT: store i32 20
+}
More information about the llvm-commits
mailing list