xref: /llvm-project/llvm/test/Transforms/Coroutines/coro-retcon-frame.ll (revision 51d5d7bbae92493a5bfa7cc6b519de8a5bb32fdb)
1; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
2
3target datalayout = "p:64:64:64"
4
5declare void @prototype_f(ptr, i1)
6
7declare noalias ptr @allocate(i32 %size)
8declare void @deallocate(ptr %ptr)
9declare void @init(ptr %ptr)
10declare void @use(ptr %ptr)
11declare void @use_addr_val(i64 %val, ptr %addr)
12
13define { ptr, ptr } @f(ptr %buffer) presplitcoroutine {
14entry:
15  %tmp = alloca { i64, i64 }, align 8
16  %proj.1 = getelementptr inbounds { i64, i64 }, ptr %tmp, i64 0, i32 0
17  %proj.2 = getelementptr inbounds { i64, i64 }, ptr %tmp, i64 0, i32 1
18  store i64 0, ptr %proj.1, align 8
19  store i64 0, ptr %proj.2, align 8
20  %escape_addr = ptrtoint ptr %tmp to i64
21  %id = call token @llvm.coro.id.retcon.once(i32 32, i32 8, ptr %buffer, ptr @prototype_f, ptr @allocate, ptr @deallocate)
22  %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
23  %proj.2.2 = getelementptr inbounds { i64, i64 }, ptr %tmp, i64 0, i32 1
24  call void @init(ptr %proj.1)
25  call void @init(ptr %proj.2.2)
26  call void @use_addr_val(i64 %escape_addr, ptr %tmp)
27  %abort = call i1 (...) @llvm.coro.suspend.retcon.i1(ptr %tmp)
28  br i1 %abort, label %end, label %resume
29
30resume:
31  call void @use(ptr %tmp)
32  br label %end
33
34end:
35  call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
36  unreachable
37}
38; Make sure we don't lose writes to the frame.
39; CHECK-LABEL: define { ptr, ptr } @f(ptr %buffer) {
40; CHECK:  [[PROJ2:%.*]] = getelementptr inbounds { i64, i64 }, ptr %buffer, i64 0, i32 1
41; CHECK:  store i64 0, ptr %buffer
42; CHECK:  store i64 0, ptr [[PROJ2]]
43; CHECK:  [[ESCAPED_ADDR:%.*]] = ptrtoint ptr %buffer to i64
44; CHECK:  call void @init(ptr %buffer)
45; CHECK:  call void @init(ptr [[PROJ2]])
46; CHECK:  call void @use_addr_val(i64 [[ESCAPED_ADDR]], ptr %buffer)
47
48; CHECK-LABEL: define internal void @f.resume.0(ptr {{.*}} %0, i1 %1) {
49; CHECK: resume:
50; CHECK:  call void @use(ptr %0)
51
52declare token @llvm.coro.id.retcon.once(i32, i32, ptr, ptr, ptr, ptr)
53declare ptr @llvm.coro.begin(token, ptr)
54declare i1 @llvm.coro.suspend.retcon.i1(...)
55declare i1 @llvm.coro.end(ptr, i1, token)
56
57