summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/GVN.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-10-28 07:05:35 +0000
committerOwen Anderson <resistor@mac.com>2009-10-28 07:05:35 +0000
commitb62f792e78df12a43029352eb4c7cde9d456c67e (patch)
treee2b4de6c1ad567c76b6038fe67a424b787a509f1 /lib/Transforms/Scalar/GVN.cpp
parent40cc524edee857eab238338200d2cc80f840f52f (diff)
downloadllvm-b62f792e78df12a43029352eb4c7cde9d456c67e.tar.gz
llvm-b62f792e78df12a43029352eb4c7cde9d456c67e.tar.bz2
llvm-b62f792e78df12a43029352eb4c7cde9d456c67e.tar.xz
Treat lifetime begin/end markers as allocations/frees respectively for the
purposes for GVN/DSE. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85383 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/GVN.cpp')
-rw-r--r--lib/Transforms/Scalar/GVN.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp
index 32d027aa36..dd8859b5e8 100644
--- a/lib/Transforms/Scalar/GVN.cpp
+++ b/lib/Transforms/Scalar/GVN.cpp
@@ -1248,6 +1248,15 @@ bool GVN::processNonLocalLoad(LoadInst *LI,
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 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl<Instruction*> &toErase) {
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;
}