xref: /llvm-project/llvm/test/Transforms/Coroutines/coro-alloca-09.ll (revision 51d5d7bbae92493a5bfa7cc6b519de8a5bb32fdb)
1; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
2
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" }
6
7declare ptr @malloc(i64)
8
9%i8.array = type { [100 x i8] }
10declare void @consume.i8(ptr)
11
12; The testval lives across suspend point so that it should be put on the frame.
13; However, part of testval has lifetime marker which indicates the part
14; wouldn't live across suspend point.
15; This test whether or not %testval would be put on the frame by ignoring the
16; partial lifetime markers.
17define void @foo(ptr %to_store) presplitcoroutine {
18entry:
19  %testval = alloca %i8.array
20  %subrange = getelementptr inbounds %i8.array, ptr %testval, i64 0, i32 0, i64 50
21  %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
22  %alloc = call ptr @malloc(i64 16) #3
23  %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
24
25  call void @llvm.lifetime.start.p0(i64 50, ptr %subrange)
26  call void @consume.i8(ptr %subrange)
27  call void @llvm.lifetime.end.p0(i64 50, ptr  %subrange)
28  store ptr %testval, ptr %to_store
29
30  %save = call token @llvm.coro.save(ptr null)
31  %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
32  switch i8 %suspend, label %exit [
33    i8 0, label %await.ready
34    i8 1, label %exit
35  ]
36await.ready:
37  %StrayCoroSave = call token @llvm.coro.save(ptr null)
38  br label %exit
39exit:
40  call i1 @llvm.coro.end(ptr null, i1 false, token none)
41  ret void
42}
43
44; Verify that for both foo and bar, testval isn't put on the frame.
45; CHECK: %foo.Frame = type { ptr, ptr, %i8.array, i1 }
46
47declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)
48declare i1 @llvm.coro.alloc(token) #3
49declare i64 @llvm.coro.size.i64() #5
50declare ptr @llvm.coro.begin(token, ptr writeonly) #3
51declare token @llvm.coro.save(ptr) #3
52declare ptr @llvm.coro.frame() #5
53declare i8 @llvm.coro.suspend(token, i1) #3
54declare ptr @llvm.coro.free(token, ptr nocapture readonly) #2
55declare i1 @llvm.coro.end(ptr, i1, token) #3
56declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #4
57declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #4
58