1 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
3 %"struct.std::coroutine_handle" = type { ptr }
4 %"struct.std::coroutine_handle.0" = type { %"struct.std::coroutine_handle" }
5 %"struct.lean_future<int>::Awaiter" = type { i32, %"struct.std::coroutine_handle.0" }
7 declare ptr @malloc(i64)
9 %i8.array = type { [100 x i8] }
10 declare void @consume.i8.array(ptr)
12 ; The lifetime of testval starts and ends before coro.suspend. Even though consume.i8.array
13 ; might capture it, we can safely say it won't live across suspension.
14 define void @foo() presplitcoroutine {
16 %testval = alloca %i8.array
17 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
18 %alloc = call ptr @malloc(i64 16) #3
19 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
21 call void @llvm.lifetime.start.p0(i64 100, ptr %testval)
22 call void @consume.i8.array(ptr %testval)
23 call void @llvm.lifetime.end.p0(i64 100, ptr %testval)
25 %save = call token @llvm.coro.save(ptr null)
26 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
27 switch i8 %suspend, label %exit [
28 i8 0, label %await.ready
32 %StrayCoroSave = call token @llvm.coro.save(ptr null)
35 call i1 @llvm.coro.end(ptr null, i1 false, token none)
39 ; The lifetime of testval starts after coro.suspend. So it will never live across suspension
41 define void @bar() presplitcoroutine {
43 %testval = alloca %i8.array
44 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
45 %alloc = call ptr @malloc(i64 16) #3
46 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
47 %save = call token @llvm.coro.save(ptr null)
48 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
49 switch i8 %suspend, label %exit [
50 i8 0, label %await.ready
54 %StrayCoroSave = call token @llvm.coro.save(ptr null)
56 call void @llvm.lifetime.start.p0(i64 100, ptr %testval)
57 call void @consume.i8.array(ptr %testval)
58 call void @llvm.lifetime.end.p0(i64 100, ptr %testval)
62 call i1 @llvm.coro.end(ptr null, i1 false, token none)
66 ; Verify that for both foo and bar, testval isn't put on the frame.
67 ; CHECK: %foo.Frame = type { ptr, ptr, i1 }
68 ; CHECK: %bar.Frame = type { ptr, ptr, i1 }
70 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
71 declare i1 @llvm.coro.alloc(token) #3
72 declare i64 @llvm.coro.size.i64() #5
73 declare ptr @llvm.coro.begin(token, ptr writeonly) #3
74 declare token @llvm.coro.save(ptr) #3
75 declare ptr @llvm.coro.frame() #5
76 declare i8 @llvm.coro.suspend(token, i1) #3
77 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #2
78 declare i1 @llvm.coro.end(ptr, i1, token) #3
79 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #4
80 declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #4