1 ; Tests that coro-split will optimize the lifetime.start maker of each local variable,
2 ; sink them to the places after the suspend block.
3 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse,simplifycfg' -S | FileCheck %s
5 %"struct.std::coroutine_handle" = type { ptr }
6 %"struct.std::coroutine_handle.0" = type { %"struct.std::coroutine_handle" }
7 %"struct.lean_future<int>::Awaiter" = type { i32, %"struct.std::coroutine_handle.0" }
9 declare ptr @malloc(i64)
10 declare void @print(i32)
11 declare void @consume.i8(i8)
13 define void @a() presplitcoroutine {
15 %ref.tmp7 = alloca %"struct.lean_future<int>::Awaiter", align 8
17 ; lifetime of %testval starts here, but not used until await.ready.
18 call void @llvm.lifetime.start.p0(i64 1, ptr %testval)
19 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
20 %alloc = call ptr @malloc(i64 16) #3
21 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
23 %save = call token @llvm.coro.save(ptr null)
24 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
25 switch i8 %suspend, label %exit [
26 i8 0, label %await.ready
30 %StrayCoroSave = call token @llvm.coro.save(ptr null)
31 %val = load i32, ptr %ref.tmp7
32 %test = load i8, ptr %testval
33 call void @consume.i8(i8 %test)
34 call void @llvm.lifetime.end.p0(i64 1, ptr %testval)
35 call void @print(i32 %val)
38 call i1 @llvm.coro.end(ptr null, i1 false, token none)
42 ; CHECK-LABEL: @a.resume(
43 ; CHECK: %testval = alloca i8, align 1
44 ; CHECK: call void @llvm.lifetime.start.p0(i64 1, ptr %testval)
45 ; CHECK-NEXT: %val = load i32, ptr %ref.tmp7
46 ; CHECK-NEXT: %test = load i8, ptr %testval
47 ; CHECK-NEXT: call void @consume.i8(i8 %test)
48 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 1, ptr %testval)
49 ; CHECK-NEXT: call void @print(i32 %val)
50 ; CHECK-NEXT: ret void
53 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
54 declare i1 @llvm.coro.alloc(token) #3
55 declare noalias nonnull ptr @"\01??2@YAPEAX_K@Z"(i64) local_unnamed_addr
56 declare i64 @llvm.coro.size.i64() #5
57 declare ptr @llvm.coro.begin(token, ptr writeonly) #3
58 declare void @"\01?puts@@YAXZZ"(...)
59 declare token @llvm.coro.save(ptr) #3
60 declare ptr @llvm.coro.frame() #5
61 declare i8 @llvm.coro.suspend(token, i1) #3
62 declare void @"\01??3@YAXPEAX@Z"(ptr) local_unnamed_addr #10
63 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #2
64 declare i1 @llvm.coro.end(ptr, i1, token) #3
65 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #4
66 declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #4