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
This commit is contained in:
Chris Lattner
2010-11-30 00:28:45 +00:00
parent 532c2f1d50
commit 201d1e56bb
3 changed files with 28 additions and 7 deletions

View File

@@ -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);
}
}
}