1 ; Tests that coro-split will convert coro.await.suspend.handle to a musttail call.
2 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck --check-prefixes=CHECK %s
3 ; RUN: opt < %s -passes='pgo-instr-gen,cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck --check-prefixes=CHECK %s
7 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
8 %alloc = call ptr @malloc(i64 16) #3
9 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
11 %save = call token @llvm.coro.save(ptr null)
12 %addr1 = call ptr @llvm.coro.subfn.addr(ptr null, i8 0)
13 call fastcc void %addr1(ptr null)
15 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
16 %cmp = icmp eq i8 %suspend, 0
17 br i1 %cmp, label %await.suspend, label %exit
19 %save2 = call token @llvm.coro.save(ptr null)
20 %br0 = call i8 @switch_result()
21 switch i8 %br0, label %unreach [
22 i8 0, label %await.resume3
23 i8 1, label %await.resume1
24 i8 2, label %await.resume2
28 call void @llvm.coro.await.suspend.handle(ptr null, ptr %hdl, ptr @await_suspend_function)
29 br label %final.suspend
32 call void @llvm.coro.await.suspend.handle(ptr null, ptr %hdl2, ptr @await_suspend_function)
33 br label %final.suspend
35 call void @llvm.coro.await.suspend.handle(ptr null, ptr null, ptr @await_suspend_function)
36 br label %final.suspend
38 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
39 %cmp2 = icmp eq i8 %suspend2, 0
40 br i1 %cmp2, label %pre.exit, label %exit
44 call i1 @llvm.coro.end(ptr null, i1 false, token none)
50 ; Verify that in the initial function resume is not marked with musttail.
52 ; CHECK: %[[addr1:.+]] = call ptr @llvm.coro.subfn.addr(ptr null, i8 0)
53 ; CHECK-NOT: musttail call fastcc void %[[addr1]](ptr null)
55 ; Verify that in the resume part resume call is marked with musttail.
56 ; CHECK-LABEL: @f.resume(
57 ; CHECK: %[[hdl:.+]] = call ptr @g()
58 ; CHECK-NEXT: call ptr @await_suspend_function
59 ; CHECK-NEXT: %[[addr2:.+]] = call ptr @llvm.coro.subfn.addr
60 ; CHECK-NEXT: musttail call fastcc void %[[addr2]]
61 ; CHECK-NEXT: ret void
62 ; CHECK: %[[hdl2:.+]] = call ptr @h()
63 ; CHECK-NEXT: call ptr @await_suspend_function
64 ; CHECK-NEXT: %[[addr3:.+]] = call ptr @llvm.coro.subfn.addr
65 ; CHECK-NEXT: musttail call fastcc void %[[addr3]]
66 ; CHECK-NEXT: ret void
67 ; CHECK: call ptr @await_suspend_function
68 ; CHECK: %[[addr4:.+]] = call ptr @llvm.coro.subfn.addr
69 ; CHECK-NEXT: musttail call fastcc void %[[addr4]]
70 ; CHECK-NEXT: ret void
73 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
74 declare i1 @llvm.coro.alloc(token) #2
75 declare i64 @llvm.coro.size.i64() #3
76 declare ptr @llvm.coro.begin(token, ptr writeonly) #2
77 declare token @llvm.coro.save(ptr) #2
78 declare ptr @llvm.coro.frame() #3
79 declare i8 @llvm.coro.suspend(token, i1) #2
80 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1
81 declare i1 @llvm.coro.end(ptr, i1, token) #2
82 declare ptr @llvm.coro.subfn.addr(ptr nocapture readonly, i8) #1
83 declare ptr @malloc(i64)
84 declare i8 @switch_result()
87 declare ptr @await_suspend_function(ptr %awaiter, ptr %hdl)
89 attributes #0 = { presplitcoroutine }
90 attributes #1 = { argmemonly nounwind readonly }
91 attributes #2 = { nounwind }
92 attributes #3 = { nounwind readnone }