[PATCH] D66950: [SimplifyCFG] Skip sinking common lifetime markers of `alloca`.
Michael Liao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 29 08:27:42 PDT 2019
hliao created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
- Similar to the workaround in fix of PR30188, skip sinking common lifetime markers of `alloca`. They are mostly left there after inlining functions in branches.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D66950
Files:
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
Index: llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
===================================================================
--- llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
+++ llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
@@ -886,6 +886,33 @@
; CHECK: ret
}
+; CHECK-LABEL: @test_not_sink_lifetime_marker
+; CHECK-NOT: select
+; CHECK: call void @llvm.lifetime.end
+; CHECK: call void @llvm.lifetime.end
+define i32 @test_not_sink_lifetime_marker(i1 zeroext %flag, i32 %x) {
+entry:
+ %y = alloca i32
+ %z = alloca i32
+ br i1 %flag, label %if.then, label %if.else
+
+if.then:
+ %y.cast = bitcast i32* %y to i8*
+ call void @llvm.lifetime.end.p0i8(i64 4, i8* %y.cast)
+ br label %if.end
+
+if.else:
+ %z.cast = bitcast i32* %z to i8*
+ call void @llvm.lifetime.end.p0i8(i64 4, i8* %z.cast)
+ br label %if.end
+
+if.end:
+ ret i32 1
+}
+
+declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
+declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
+
; CHECK: ![[$TBAA]] = !{![[TYPE:[0-9]]], ![[TYPE]], i64 0}
; CHECK: ![[TYPE]] = !{!"float", ![[TEXT:[0-9]]]}
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1484,11 +1484,29 @@
// FIXME: This is a workaround for a deficiency in SROA - see
// https://llvm.org/bugs/show_bug.cgi?id=30188
if (isa<StoreInst>(I0) && any_of(Insts, [](const Instruction *I) {
- return isa<AllocaInst>(I->getOperand(1));
+ return isa<AllocaInst>(I->getOperand(1)->stripPointerCasts());
}))
return false;
if (isa<LoadInst>(I0) && any_of(Insts, [](const Instruction *I) {
- return isa<AllocaInst>(I->getOperand(0));
+ return isa<AllocaInst>(I->getOperand(0)->stripPointerCasts());
+ }))
+ return false;
+
+ auto isLifeTimeMarker = [](const Instruction *I) {
+ if (auto II = dyn_cast<IntrinsicInst>(I)) {
+ switch (II->getIntrinsicID()) {
+ default:
+ break;
+ case Intrinsic::lifetime_start:
+ case Intrinsic::lifetime_end:
+ return true;
+ }
+ }
+ return false;
+ };
+
+ if (isLifeTimeMarker(I0) && any_of(Insts, [](const Instruction *I) {
+ return isa<AllocaInst>(I->getOperand(1)->stripPointerCasts());
}))
return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66950.217890.patch
Type: text/x-patch
Size: 2390 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190829/79348cc8/attachment.bin>
More information about the llvm-commits
mailing list