[PATCH] D66604: [GVN] AnalyzeLoadAvailability: Replace a load after lifetime.end with undef (PR20811)
Shreyansh Chouhan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 1 09:44:31 PDT 2019
BK1603 updated this revision to Diff 218267.
BK1603 added a comment.
Replaced conditionals at original position.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66604/new/
https://reviews.llvm.org/D66604
Files:
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/test/Transforms/GVN/lifetime-end.ll
Index: llvm/test/Transforms/GVN/lifetime-end.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/GVN/lifetime-end.ll
@@ -0,0 +1,13 @@
+; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
+
+define i8 @test(i8* %P) nounwind {
+; CHECK: lifetime.end
+; CHECK-NOT: load
+; CHECK: ret i8 undef
+entry:
+ call void @llvm.lifetime.end(i64 32, i8* %P)
+ %0 = load i8, i8* %P
+ ret i8 %0
+}
+
+declare void @llvm.lifetime.end(i64 %S, i8* nocapture %P)
Index: llvm/lib/Transforms/Scalar/GVN.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/GVN.cpp
+++ llvm/lib/Transforms/Scalar/GVN.cpp
@@ -822,6 +822,12 @@
return false;
}
+static bool isLifetimeEnd(const Instruction *Inst) {
+ if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst))
+ return II->getIntrinsicID() == Intrinsic::lifetime_end;
+ return false;
+}
+
/// Try to locate the three instruction involved in a missed
/// load-elimination case that is due to an intervening store.
static void reportMayClobberedLoad(LoadInst *LI, MemDepResult DepInfo,
@@ -864,7 +870,15 @@
const DataLayout &DL = LI->getModule()->getDataLayout();
Instruction *DepInst = DepInfo.getInst();
+
if (DepInfo.isClobber()) {
+
+ // Load immediately after lifetime end -> undef
+ if(isLifetimeEnd(DepInst)) {
+ Res = AvailableValue::get(UndefValue::get(LI->getType()));
+ return true;
+ }
+
// If the dependence is to a store that writes to a superset of the bits
// read by the load, we can extract the bits we need for the load from the
// stored value.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66604.218267.patch
Type: text/x-patch
Size: 1644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190901/6a6959af/attachment.bin>
More information about the llvm-commits
mailing list