Skip to content

Commit 243e62b

Browse files
committed
[Coroutines] Directly remove unnecessary lifetime intrinsics
The insertSpills() code will currently skip lifetime intrinsic users when replacing the alloca with a frame reference. Rather than leaving behind the dead lifetime intrinsics working on the old alloca, directly remove them. This makes sure the alloca can be dropped as well. I noticed this as a regression when converting tests to opaque pointers. Without opaque pointers, this code didn't really do anything, because there would usually be a bitcast in between. The lifetimes would get rewritten to the frame pointer. With opaque pointers, this code now triggers and leaves behind users of the old allocas. Differential Revision: https://reviews.llvm.org/D148240
1 parent de4c038 commit 243e62b

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

clang/test/CodeGenCoroutines/coro-always-inline.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ struct coroutine_traits {
3333

3434
// CHECK-LABEL: @_Z3foov
3535
// CHECK-LABEL: entry:
36-
// CHECK: call void @llvm.lifetime.start.p0(i64 1, ptr %ref.tmp{{.*}})
37-
// CHECK: call void @llvm.lifetime.end.p0(i64 1, ptr %ref.tmp{{.*}})
38-
39-
// CHECK: call void @llvm.lifetime.start.p0(i64 1, ptr %ref.tmp{{.*}})
40-
// CHECK: call void @llvm.lifetime.end.p0(i64 1, ptr %ref.tmp{{.*}})
36+
// CHECK: %ref.tmp.reload.addr = getelementptr
37+
// CHECK: %ref.tmp4.reload.addr = getelementptr
4138
void foo() { co_return; }
4239

4340
// Check that bar is not inlined even it's marked as always_inline.

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,11 +1946,13 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
19461946
DVI->replaceUsesOfWith(Alloca, G);
19471947

19481948
for (Instruction *I : UsersToUpdate) {
1949-
// It is meaningless to remain the lifetime intrinsics refer for the
1949+
// It is meaningless to retain the lifetime intrinsics refer for the
19501950
// member of coroutine frames and the meaningless lifetime intrinsics
19511951
// are possible to block further optimizations.
1952-
if (I->isLifetimeStartOrEnd())
1952+
if (I->isLifetimeStartOrEnd()) {
1953+
I->eraseFromParent();
19531954
continue;
1955+
}
19541956

19551957
I->replaceUsesOfWith(Alloca, G);
19561958
}

llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
define void @foo() presplitcoroutine {
88
; CHECK-LABEL: @foo(
99
; CHECK-NEXT: entry:
10-
; CHECK-NEXT: [[STACKVAR0:%.*]] = alloca i64, align 8
1110
; CHECK-NEXT: [[ID:%.*]] = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr @foo.resumers)
1211
; CHECK-NEXT: [[ALLOC:%.*]] = call ptr @malloc(i64 40)
1312
; CHECK-NEXT: [[VFRAME:%.*]] = call noalias nonnull ptr @llvm.coro.begin(token [[ID]], ptr [[ALLOC]])

0 commit comments

Comments
 (0)