[llvm-commits] [llvm] r49842 - in /llvm/trunk: lib/Analysis/MemoryDependenceAnalysis.cpp lib/Transforms/Scalar/GVN.cpp test/Analysis/BasicAA/const-dce.ll test/Analysis/BasicAA/pure-const-dce.ll
Owen Anderson
resistor at mac.com
Wed Apr 16 22:36:50 PDT 2008
Author: resistor
Date: Thu Apr 17 00:36:50 2008
New Revision: 49842
URL: http://llvm.org/viewvc/llvm-project?rev=49842&view=rev
Log:
Make GVN able to remove unnecessary calls to read-only functions again.
Added:
llvm/trunk/test/Analysis/BasicAA/pure-const-dce.ll
Removed:
llvm/trunk/test/Analysis/BasicAA/const-dce.ll
Modified:
llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
llvm/trunk/lib/Transforms/Scalar/GVN.cpp
Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=49842&r1=49841&r2=49842&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Thu Apr 17 00:36:50 2008
@@ -134,8 +134,7 @@
} else if (isa<CallInst>(QI)) {
AliasAnalysis::ModRefBehavior result =
AA.getModRefBehavior(CallSite::get(QI));
- if (result != AliasAnalysis::DoesNotAccessMemory &&
- result != AliasAnalysis::OnlyReadsMemory) {
+ if (result != AliasAnalysis::DoesNotAccessMemory) {
if (!start && !block) {
cachedResult.first = QI;
cachedResult.second = true;
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=49842&r1=49841&r2=49842&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Thu Apr 17 00:36:50 2008
@@ -135,6 +135,7 @@
DenseMap<Value*, uint32_t> valueNumbering;
DenseMap<Expression, uint32_t> expressionNumbering;
AliasAnalysis* AA;
+ MemoryDependenceAnalysis* MD;
uint32_t nextValueNumber;
@@ -159,6 +160,7 @@
void erase(Value* v);
unsigned size();
void setAliasAnalysis(AliasAnalysis* A) { AA = A; }
+ void setMemDep(MemoryDependenceAnalysis* M) { MD = M; }
};
}
@@ -432,6 +434,33 @@
return nextValueNumber++;
}
+ } else if (AA->onlyReadsMemory(C)) {
+ Expression e = create_expression(C);
+
+ Instruction* dep = MD->getDependency(C);
+
+ if (dep == MemoryDependenceAnalysis::NonLocal ||
+ !isa<CallInst>(dep)) {
+ expressionNumbering.insert(std::make_pair(e, nextValueNumber));
+ valueNumbering.insert(std::make_pair(V, nextValueNumber));
+
+ return nextValueNumber++;
+ }
+
+ CallInst* cdep = cast<CallInst>(dep);
+ Expression d_exp = create_expression(cdep);
+
+ if (e != d_exp) {
+ expressionNumbering.insert(std::make_pair(e, nextValueNumber));
+ valueNumbering.insert(std::make_pair(V, nextValueNumber));
+
+ return nextValueNumber++;
+ } else {
+ uint32_t v = expressionNumbering[d_exp];
+ valueNumbering.insert(std::make_pair(V, v));
+ return v;
+ }
+
} else {
valueNumbering.insert(std::make_pair(V, nextValueNumber));
return nextValueNumber++;
@@ -993,22 +1022,6 @@
} else if (currAvail.test(num)) {
Value* repl = find_leader(currAvail, num);
- if (CallInst* CI = dyn_cast<CallInst>(I)) {
- AliasAnalysis& AA = getAnalysis<AliasAnalysis>();
- if (!AA.doesNotAccessMemory(CI)) {
- MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
- if (cast<Instruction>(repl)->getParent() != CI->getParent() ||
- 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;
- }
- }
- }
-
// Remove it!
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
MD.removeInstruction(I);
@@ -1030,6 +1043,7 @@
//
bool GVN::runOnFunction(Function& F) {
VN.setAliasAnalysis(&getAnalysis<AliasAnalysis>());
+ VN.setMemDep(&getAnalysis<MemoryDependenceAnalysis>());
bool changed = false;
bool shouldContinue = true;
Removed: llvm/trunk/test/Analysis/BasicAA/const-dce.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BasicAA/const-dce.ll?rev=49841&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/BasicAA/const-dce.ll (original)
+++ llvm/trunk/test/Analysis/BasicAA/const-dce.ll (removed)
@@ -1,33 +0,0 @@
-; RUN: llvm-as < %s | opt -basicaa -gvn | llvm-dis | grep TestConst | count 2
-; RUN: llvm-as < %s | opt -basicaa -gvn | llvm-dis | grep TestPure | count 4
-; RUN: llvm-as < %s | opt -basicaa -gvn | llvm-dis | grep TestNone | count 4
- at g = global i32 0 ; <i32*> [#uses=1]
-
-define i32 @test() {
-entry:
- %tmp0 = call i32 @TestConst( i32 5 ) readnone ; <i32> [#uses=1]
- %tmp1 = call i32 @TestPure( i32 6 ) readonly ; <i32> [#uses=1]
- %tmp2 = call i32 @TestNone( i32 7 ) ; <i32> [#uses=1]
- store i32 1, i32* @g
- %tmp3 = call i32 @TestConst( i32 5 ) readnone ; <i32> [#uses=1]
- %tmp4 = call i32 @TestConst( i32 5 ) readnone ; <i32> [#uses=1]
- %tmp5 = call i32 @TestPure( i32 6 ) readonly ; <i32> [#uses=1]
- %tmp6 = call i32 @TestPure( i32 6 ) readonly ; <i32> [#uses=1]
- %tmp7 = call i32 @TestNone( i32 7 ) ; <i32> [#uses=1]
- %tmp8 = call i32 @TestNone( i32 7 ) ; <i32> [#uses=1]
- %sum0 = add i32 %tmp0, %tmp1 ; <i32> [#uses=1]
- %sum1 = add i32 %sum0, %tmp2 ; <i32> [#uses=1]
- %sum2 = add i32 %sum1, %tmp3 ; <i32> [#uses=1]
- %sum3 = add i32 %sum2, %tmp4 ; <i32> [#uses=1]
- %sum4 = add i32 %sum3, %tmp5 ; <i32> [#uses=1]
- %sum5 = add i32 %sum4, %tmp6 ; <i32> [#uses=1]
- %sum6 = add i32 %sum5, %tmp7 ; <i32> [#uses=1]
- %sum7 = add i32 %sum6, %tmp8 ; <i32> [#uses=1]
- ret i32 %sum7
-}
-
-declare i32 @TestConst(i32) readnone
-
-declare i32 @TestPure(i32) readonly
-
-declare i32 @TestNone(i32)
Added: 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=49842&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/BasicAA/pure-const-dce.ll (added)
+++ llvm/trunk/test/Analysis/BasicAA/pure-const-dce.ll Thu Apr 17 00:36:50 2008
@@ -0,0 +1,33 @@
+; RUN: llvm-as < %s | opt -basicaa -gvn | llvm-dis | grep TestConst | 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
+ at g = global i32 0 ; <i32*> [#uses=1]
+
+define i32 @test() {
+entry:
+ %tmp0 = call i32 @TestConst( i32 5 ) readnone ; <i32> [#uses=1]
+ %tmp1 = call i32 @TestPure( i32 6 ) readonly ; <i32> [#uses=1]
+ %tmp2 = call i32 @TestNone( i32 7 ) ; <i32> [#uses=1]
+ store i32 1, i32* @g
+ %tmp3 = call i32 @TestConst( i32 5 ) readnone ; <i32> [#uses=1]
+ %tmp4 = call i32 @TestConst( i32 5 ) readnone ; <i32> [#uses=1]
+ %tmp5 = call i32 @TestPure( i32 6 ) readonly ; <i32> [#uses=1]
+ %tmp6 = call i32 @TestPure( i32 6 ) readonly ; <i32> [#uses=1]
+ %tmp7 = call i32 @TestNone( i32 7 ) ; <i32> [#uses=1]
+ %tmp8 = call i32 @TestNone( i32 7 ) ; <i32> [#uses=1]
+ %sum0 = add i32 %tmp0, %tmp1 ; <i32> [#uses=1]
+ %sum1 = add i32 %sum0, %tmp2 ; <i32> [#uses=1]
+ %sum2 = add i32 %sum1, %tmp3 ; <i32> [#uses=1]
+ %sum3 = add i32 %sum2, %tmp4 ; <i32> [#uses=1]
+ %sum4 = add i32 %sum3, %tmp5 ; <i32> [#uses=1]
+ %sum5 = add i32 %sum4, %tmp6 ; <i32> [#uses=1]
+ %sum6 = add i32 %sum5, %tmp7 ; <i32> [#uses=1]
+ %sum7 = add i32 %sum6, %tmp8 ; <i32> [#uses=1]
+ ret i32 %sum7
+}
+
+declare i32 @TestConst(i32) readnone
+
+declare i32 @TestPure(i32) readonly
+
+declare i32 @TestNone(i32)
More information about the llvm-commits
mailing list