xref: /llvm-project/llvm/test/Transforms/Coroutines/coro-split-musttail6.ll (revision 3bb39690d729d85cd93c9dd6e750d82d6f367541)
1; Tests that sinked lifetime markers wouldn't provent optimization
2; to convert a coro.await.suspend.handle call to a musttail call.
3; The difference between this and coro-split-musttail5.ll is that there is
4; an extra bitcast instruction in the path, which makes it harder to
5; optimize.
6; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
7; RUN: opt < %s -passes='pgo-instr-gen,cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
8
9declare void @fakeresume1(ptr align 8)
10
11define void @g() #0 {
12entry:
13  %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
14  %alloc = call ptr @malloc(i64 16) #3
15  %alloc.var = alloca i64
16  call void @llvm.lifetime.start.p0(i64 1, ptr %alloc.var)
17  %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
18
19  %save = call token @llvm.coro.save(ptr null)
20  %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
21
22  switch i8 %suspend, label %exit [
23    i8 0, label %await.suspend
24    i8 1, label %exit
25  ]
26await.suspend:
27  %save2 = call token @llvm.coro.save(ptr null)
28  call void @llvm.coro.await.suspend.handle(ptr null, ptr null, ptr @await_suspend_function)
29  %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
30  switch i8 %suspend2, label %exit [
31    i8 0, label %await.ready
32    i8 1, label %exit
33  ]
34await.ready:
35  call void @consume(ptr %alloc.var)
36  call void @llvm.lifetime.end.p0(i64 1, ptr %alloc.var)
37  br label %exit
38exit:
39  call i1 @llvm.coro.end(ptr null, i1 false, token none)
40  ret void
41}
42
43; Verify that in the resume part resume call is marked with musttail.
44; CHECK-LABEL: @g.resume(
45; CHECK:      musttail call fastcc void
46; CHECK-NEXT: ret void
47
48; It has a cleanup bb.
49define void @f() #0 {
50entry:
51  %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
52  %alloc = call ptr @malloc(i64 16) #3
53  %alloc.var = alloca i64
54  call void @llvm.lifetime.start.p0(i64 1, ptr %alloc.var)
55  %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
56
57  %save = call token @llvm.coro.save(ptr null)
58  %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
59
60  switch i8 %suspend, label %exit [
61    i8 0, label %await.suspend
62    i8 1, label %exit
63  ]
64await.suspend:
65  %save2 = call token @llvm.coro.save(ptr null)
66  call void @llvm.coro.await.suspend.handle(ptr null, ptr null, ptr @await_suspend_function)
67  %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
68  switch i8 %suspend2, label %exit [
69    i8 0, label %await.ready
70    i8 1, label %cleanup
71  ]
72await.ready:
73  call void @consume(ptr %alloc.var)
74  call void @llvm.lifetime.end.p0(i64 1, ptr %alloc.var)
75  br label %exit
76
77cleanup:
78  %free.handle = call ptr @llvm.coro.free(token %id, ptr %vFrame)
79  %.not = icmp eq ptr %free.handle, null
80  br i1 %.not, label %exit, label %coro.free
81
82coro.free:
83  call void @delete(ptr nonnull %free.handle) #2
84  br label %exit
85
86exit:
87  call i1 @llvm.coro.end(ptr null, i1 false, token none)
88  ret void
89}
90
91; Verify that in the resume part resume call is marked with musttail.
92; CHECK-LABEL: @f.resume(
93; CHECK:      musttail call fastcc void
94; CHECK-NEXT: ret void
95
96declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
97declare i1 @llvm.coro.alloc(token) #2
98declare i64 @llvm.coro.size.i64() #3
99declare ptr @llvm.coro.begin(token, ptr writeonly) #2
100declare token @llvm.coro.save(ptr) #2
101declare ptr @llvm.coro.frame() #3
102declare i8 @llvm.coro.suspend(token, i1) #2
103declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1
104declare i1 @llvm.coro.end(ptr, i1, token) #2
105declare ptr @llvm.coro.subfn.addr(ptr nocapture readonly, i8) #1
106declare ptr @malloc(i64)
107declare void @delete(ptr nonnull) #2
108declare void @consume(ptr)
109declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
110declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
111declare ptr @await_suspend_function(ptr %awaiter, ptr %hdl)
112
113attributes #0 = { presplitcoroutine }
114attributes #1 = { argmemonly nounwind readonly }
115attributes #2 = { nounwind }
116attributes #3 = { nounwind readnone }
117