diff options
author | Owen Anderson <resistor@mac.com> | 2007-11-26 02:26:36 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2007-11-26 02:26:36 +0000 |
commit | 4f833c7610f51cc9f7e156261b2dd49c5d74ceab (patch) | |
tree | c0df9758eb1a26280e24b036e80928b17dceae59 /llvm/lib/Transforms | |
parent | 2ab40a6207d3a522a81beb300a5cb560eef81299 (diff) | |
download | bcm5719-llvm-4f833c7610f51cc9f7e156261b2dd49c5d74ceab.tar.gz bcm5719-llvm-4f833c7610f51cc9f7e156261b2dd49c5d74ceab.zip |
Allow GVN to eliminate read-only function calls when it can detect that they are redundant.
llvm-svn: 44323
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/GVN.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp index 7cbd617a2eb..11fa336c7bb 100644 --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -476,7 +476,8 @@ uint32_t ValueTable::lookup_or_add(Value* V) { if (CallInst* C = dyn_cast<CallInst>(V)) { if (C->getCalledFunction() && - AA->doesNotAccessMemory(C->getCalledFunction())) { + (AA->doesNotAccessMemory(C->getCalledFunction()) || + AA->onlyReadsMemory(C->getCalledFunction()))) { Expression e = create_expression(C); DenseMap<Expression, uint32_t>::iterator EI = expressionNumbering.find(e); @@ -1038,6 +1039,22 @@ bool GVN::processInstruction(Instruction* I, } else if (currAvail.test(num)) { Value* repl = find_leader(currAvail, num); + if (CallInst* CI = dyn_cast<CallInst>(I)) { + AliasAnalysis& AA = getAnalysis<AliasAnalysis>(); + if (CI->getCalledFunction() && + !AA.doesNotAccessMemory(CI->getCalledFunction())) { + MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>(); + if (MD.getDependency(CI) != MD.getDependency(cast<CallInst>(repl))) { + // There must be an intervening may-alias store, so nothing from + // this point on will be able to be replaced with the preceding call + currAvail.erase(repl); + currAvail.insert(I); + + return false; + } + } + } + VN.erase(I); I->replaceAllUsesWith(repl); toErase.push_back(I); |