[llvm-commits] [llvm] r85383 - in /llvm/trunk: lib/Analysis/MemoryDependenceAnalysis.cpp lib/Transforms/Scalar/DeadStoreElimination.cpp lib/Transforms/Scalar/GVN.cpp test/Transforms/DeadStoreElimination/lifetime-simple.ll test/Transforms/GVN/lifetime-simple.ll
Owen Anderson
resistor at mac.com
Wed Oct 28 00:05:35 PDT 2009
Author: resistor
Date: Wed Oct 28 02:05:35 2009
New Revision: 85383
URL: http://llvm.org/viewvc/llvm-project?rev=85383&view=rev
Log:
Treat lifetime begin/end markers as allocations/frees respectively for the
purposes for GVN/DSE.
Added:
llvm/trunk/test/Transforms/DeadStoreElimination/lifetime-simple.ll
llvm/trunk/test/Transforms/GVN/lifetime-simple.ll
Modified:
llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.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=85383&r1=85382&r2=85383&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Wed Oct 28 02:05:35 2009
@@ -185,10 +185,9 @@
if (invariantTag == Inst) {
invariantTag = 0;
continue;
-
- // If we pass an invariant-end marker, then we've just entered an invariant
- // region and can start ignoring dependencies.
} else if (IntrinsicInst* II = dyn_cast<IntrinsicInst>(Inst)) {
+ // If we pass an invariant-end marker, then we've just entered an
+ // invariant region and can start ignoring dependencies.
if (II->getIntrinsicID() == Intrinsic::invariant_end) {
uint64_t invariantSize = ~0ULL;
if (ConstantInt* CI = dyn_cast<ConstantInt>(II->getOperand(2)))
@@ -200,6 +199,19 @@
invariantTag = II->getOperand(1);
continue;
}
+
+ // If we reach a lifetime begin or end marker, then the query ends here
+ // because the value is undefined.
+ } else if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
+ II->getIntrinsicID() == Intrinsic::lifetime_end) {
+ uint64_t invariantSize = ~0ULL;
+ if (ConstantInt* CI = dyn_cast<ConstantInt>(II->getOperand(1)))
+ invariantSize = CI->getZExtValue();
+
+ AliasAnalysis::AliasResult R =
+ AA->alias(II->getOperand(2), invariantSize, MemPtr, MemSize);
+ if (R == AliasAnalysis::MustAlias)
+ return MemDepResult::getDef(II);
}
}
Modified: llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp?rev=85383&r1=85382&r2=85383&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp Wed Oct 28 02:05:35 2009
@@ -154,6 +154,26 @@
continue;
}
}
+
+ // If this is a lifetime end marker, we can throw away the store.
+ if (IntrinsicInst* II = dyn_cast<IntrinsicInst>(InstDep.getInst())) {
+ if (II->getIntrinsicID() == Intrinsic::lifetime_end) {
+ // Delete the store and now-dead instructions that feed it.
+ // DeleteDeadInstruction can delete the current instruction. Save BBI
+ // in case we need it.
+ WeakVH NextInst(BBI);
+
+ DeleteDeadInstruction(SI);
+
+ if (NextInst == 0) // Next instruction deleted.
+ BBI = BB.begin();
+ else if (BBI != BB.begin()) // Revisit this instruction if possible.
+ --BBI;
+ NumFastStores++;
+ MadeChange = true;
+ continue;
+ }
+ }
}
// If this block ends in a return, unwind, or unreachable, all allocas are
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=85383&r1=85382&r2=85383&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Wed Oct 28 02:05:35 2009
@@ -1248,6 +1248,15 @@
UndefValue::get(LI->getType())));
continue;
}
+
+ // Loading immediately after lifetime begin or end -> undef.
+ if (IntrinsicInst* II = dyn_cast<IntrinsicInst>(DepInst)) {
+ if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
+ II->getIntrinsicID() == Intrinsic::lifetime_end) {
+ ValuesPerBlock.push_back(AvailableValueInBlock::get(DepBB,
+ UndefValue::get(LI->getType())));
+ }
+ }
if (StoreInst *S = dyn_cast<StoreInst>(DepInst)) {
// Reject loads and stores that are to the same address but are of
@@ -1591,6 +1600,18 @@
NumGVNLoad++;
return true;
}
+
+ // If this load occurs either right after a lifetime begin or a lifetime end,
+ // then the loaded value is undefined.
+ if (IntrinsicInst* II = dyn_cast<IntrinsicInst>(DepInst)) {
+ if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
+ II->getIntrinsicID() == Intrinsic::lifetime_end) {
+ L->replaceAllUsesWith(UndefValue::get(L->getType()));
+ toErase.push_back(L);
+ NumGVNLoad++;
+ return true;
+ }
+ }
return false;
}
Added: llvm/trunk/test/Transforms/DeadStoreElimination/lifetime-simple.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DeadStoreElimination/lifetime-simple.ll?rev=85383&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/DeadStoreElimination/lifetime-simple.ll (added)
+++ llvm/trunk/test/Transforms/DeadStoreElimination/lifetime-simple.ll Wed Oct 28 02:05:35 2009
@@ -0,0 +1,18 @@
+; RUN: opt < %s -dse -S | FileCheck %s
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+
+define i8 @test2(i8* %P) nounwind {
+; CHECK: @test2
+; CHECK-NOT: store i8 1
+; CHECK: ret i8 0
+entry:
+ call void @llvm.lifetime.start(i64 32, i8* %P)
+ call void @llvm.lifetime.end(i64 32, i8* %P)
+ store i8 1, i8* %P
+ ret i8 0
+}
+
+declare {}* @llvm.lifetime.start(i64 %S, i8* nocapture %P) readonly
+declare void @llvm.lifetime.end(i64 %S, i8* nocapture %P)
\ No newline at end of file
Added: llvm/trunk/test/Transforms/GVN/lifetime-simple.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/lifetime-simple.ll?rev=85383&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GVN/lifetime-simple.ll (added)
+++ llvm/trunk/test/Transforms/GVN/lifetime-simple.ll Wed Oct 28 02:05:35 2009
@@ -0,0 +1,20 @@
+; RUN: opt < %s -gvn -S | FileCheck %s
+
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
+target triple = "i386-apple-darwin7"
+
+define i8 @test(i8* %P) nounwind {
+; CHECK: @test
+; CHECK-NOT: load
+; CHECK: ret i8 undef
+entry:
+ call void @llvm.lifetime.start(i64 32, i8* %P)
+ %0 = load i8* %P
+ store i8 1, i8* %P
+ call void @llvm.lifetime.end(i64 32, i8* %P)
+ %1 = load i8* %P
+ ret i8 %1
+}
+
+declare {}* @llvm.lifetime.start(i64 %S, i8* nocapture %P) readonly
+declare void @llvm.lifetime.end(i64 %S, i8* nocapture %P)
\ No newline at end of file
More information about the llvm-commits
mailing list