aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar/DeadStoreElimination.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-11-30 00:28:45 +0000
committerChris Lattner <sabre@nondot.org>2010-11-30 00:28:45 +0000
commit201d1e56bb7535802c70d5eb46601afcc325045d (patch)
tree06126f5e9e4f595a6bf9392503975886c6ddfdb3 /lib/Transforms/Scalar/DeadStoreElimination.cpp
parent532c2f1d503a42c5e8e0c5c9a513c459fed73d25 (diff)
downloadexternal_llvm-201d1e56bb7535802c70d5eb46601afcc325045d.zip
external_llvm-201d1e56bb7535802c70d5eb46601afcc325045d.tar.gz
external_llvm-201d1e56bb7535802c70d5eb46601afcc325045d.tar.bz2
Teach basicaa that memset's modref set is at worst "mod" and never
contains "ref". Enhance DSE to use a modref query instead of a store-specific hack to generalize the "ignore may-alias stores" optimization to handle memset and memcpy. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120368 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/DeadStoreElimination.cpp')
-rw-r--r--lib/Transforms/Scalar/DeadStoreElimination.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp
index dd66416..d9f5bc5 100644
--- a/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -191,6 +191,7 @@ static bool isStoreAtLeastAsWideAs(Instruction *I1, Instruction *I2,
I1Size >= I2Size;
}
+
bool DSE::runOnBasicBlock(BasicBlock &BB) {
MemoryDependenceAnalysis &MD = getAnalysis<MemoryDependenceAnalysis>();
TD = getAnalysisIfAvailable<TargetData>();
@@ -239,7 +240,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
}
}
}
-
+
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
@@ -250,12 +251,16 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
// 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);
+ AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
+ AliasAnalysis::Location Loc = AA.getLocation(SI);
+ while (InstDep.isClobber() && InstDep.getInst() != &BB.front()) {
+ // Can't look past this instruction if it might read 'Loc'.
+ if (AA.getModRefInfo(InstDep.getInst(), Loc) & AliasAnalysis::Ref)
+ break;
+
+ InstDep = MD.getPointerDependencyFrom(Loc, false,
+ InstDep.getInst(), &BB);
+ }
}
}