[llvm-commits] [llvm] r44323 - in /llvm/trunk: lib/Analysis/MemoryDependenceAnalysis.cpp lib/Transforms/Scalar/GVN.cpp test/Analysis/BasicAA/pure-const-dce.ll
Owen Anderson
resistor at mac.com
Sun Nov 25 18:26:36 PST 2007
Author: resistor
Date: Sun Nov 25 20:26:36 2007
New Revision: 44323
URL: http://llvm.org/viewvc/llvm-project?rev=44323&view=rev
Log:
Allow GVN to eliminate read-only function calls when it can detect that they are redundant.
Modified:
llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
llvm/trunk/lib/Transforms/Scalar/GVN.cpp
llvm/trunk/test/Analysis/BasicAA/pure-const-dce.ll
Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=44323&r1=44322&r2=44323&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Sun Nov 25 20:26:36 2007
@@ -79,9 +79,6 @@
if (StoreInst* S = dyn_cast<StoreInst>(QI)) {
pointer = S->getPointerOperand();
pointerSize = TD.getTypeStoreSize(S->getOperand(0)->getType());
- } else if (LoadInst* L = dyn_cast<LoadInst>(QI)) {
- pointer = L->getPointerOperand();
- pointerSize = TD.getTypeStoreSize(L->getType());
} else if (AllocationInst* AI = dyn_cast<AllocationInst>(QI)) {
pointer = AI;
if (ConstantInt* C = dyn_cast<ConstantInt>(AI->getArraySize()))
@@ -98,7 +95,11 @@
// FreeInsts erase the entire structure
pointerSize = ~0UL;
} else if (CallSite::get(QI).getInstruction() != 0) {
- if (AA.getModRefInfo(C, CallSite::get(QI)) != AliasAnalysis::NoModRef) {
+ AliasAnalysis::ModRefBehavior result =
+ AA.getModRefBehavior(cast<CallInst>(QI)->getCalledFunction(),
+ CallSite::get(QI));
+ if (result != AliasAnalysis::DoesNotAccessMemory &&
+ result != AliasAnalysis::OnlyReadsMemory) {
if (!start && !block) {
depGraphLocal.insert(std::make_pair(C.getInstruction(),
std::make_pair(QI, true)));
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=44323&r1=44322&r2=44323&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Sun Nov 25 20:26:36 2007
@@ -476,7 +476,8 @@
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 @@
} 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);
Modified: llvm/trunk/test/Analysis/BasicAA/pure-const-dce.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BasicAA/pure-const-dce.ll?rev=44323&r1=44322&r2=44323&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BasicAA/pure-const-dce.ll (original)
+++ llvm/trunk/test/Analysis/BasicAA/pure-const-dce.ll Sun Nov 25 20:26:36 2007
@@ -1,5 +1,5 @@
; RUN: llvm-as < %s | opt -basicaa -gvn | llvm-dis | grep TestConst | count 2
-; RUN: llvm-as < %s | opt -basicaa -gvn | llvm-dis | grep TestPure | not count 2
+; RUN: llvm-as < %s | opt -basicaa -gvn | llvm-dis | grep TestPure | count 3
; RUN: llvm-as < %s | opt -basicaa -gvn | llvm-dis | grep TestNone | count 4
@g = global i32 0 ; <i32*> [#uses=1]
More information about the llvm-commits
mailing list