1 ; Tests that coro-split will convert coro.resume followed by a suspend to a
3 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
7 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
8 %alloc = call i8* @malloc(i64 16) #3
9 %vFrame = call noalias nonnull i8* @llvm.coro.begin(token %id, i8* %alloc)
11 %save = call token @llvm.coro.save(i8* null)
12 %addr1 = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
13 %pv1 = bitcast i8* %addr1 to void (i8*)*
14 call fastcc void %pv1(i8* null)
16 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
17 %cmp = icmp eq i8 %suspend, 0
18 br i1 %cmp, label %await.suspend, label %exit
20 %save2 = call token @llvm.coro.save(i8* null)
21 %br0 = call i8 @switch_result()
22 switch i8 %br0, label %unreach [
23 i8 0, label %await.resume3
24 i8 1, label %await.resume1
25 i8 2, label %await.resume2
29 %addr2 = call i8* @llvm.coro.subfn.addr(i8* %hdl, i8 0)
30 %pv2 = bitcast i8* %addr2 to void (i8*)*
31 call fastcc void %pv2(i8* %hdl)
32 br label %final.suspend
35 %addr3 = call i8* @llvm.coro.subfn.addr(i8* %hdl2, i8 0)
36 %pv3 = bitcast i8* %addr3 to void (i8*)*
37 call fastcc void %pv3(i8* %hdl2)
38 br label %final.suspend
40 %addr4 = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
41 %pv4 = bitcast i8* %addr4 to void (i8*)*
42 call fastcc void %pv4(i8* null)
43 br label %final.suspend
45 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
46 %cmp2 = icmp eq i8 %suspend2, 0
47 br i1 %cmp2, label %pre.exit, label %exit
51 call i1 @llvm.coro.end(i8* null, i1 false)
57 ; Verify that in the initial function resume is not marked with musttail.
59 ; CHECK: %[[addr1:.+]] = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
60 ; CHECK-NEXT: %[[pv1:.+]] = bitcast i8* %[[addr1]] to void (i8*)*
61 ; CHECK-NOT: musttail call fastcc void %[[pv1]](i8* null)
63 ; Verify that in the resume part resume call is marked with musttail.
64 ; CHECK-LABEL: @f.resume(
65 ; CHECK: %[[hdl:.+]] = call i8* @g()
66 ; CHECK-NEXT: %[[addr2:.+]] = call i8* @llvm.coro.subfn.addr(i8* %[[hdl]], i8 0)
67 ; CHECK-NEXT: %[[pv2:.+]] = bitcast i8* %[[addr2]] to void (i8*)*
68 ; CHECK-NEXT: musttail call fastcc void %[[pv2]](i8* %[[hdl]])
69 ; CHECK-NEXT: ret void
70 ; CHECK: %[[hdl2:.+]] = call i8* @h()
71 ; CHECK-NEXT: %[[addr3:.+]] = call i8* @llvm.coro.subfn.addr(i8* %[[hdl2]], i8 0)
72 ; CHECK-NEXT: %[[pv3:.+]] = bitcast i8* %[[addr3]] to void (i8*)*
73 ; CHECK-NEXT: musttail call fastcc void %[[pv3]](i8* %[[hdl2]])
74 ; CHECK-NEXT: ret void
75 ; CHECK: %[[addr4:.+]] = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
76 ; CHECK-NEXT: %[[pv4:.+]] = bitcast i8* %[[addr4]] to void (i8*)*
77 ; CHECK-NEXT: musttail call fastcc void %[[pv4]](i8* null)
78 ; CHECK-NEXT: ret void
82 declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*) #1
83 declare i1 @llvm.coro.alloc(token) #2
84 declare i64 @llvm.coro.size.i64() #3
85 declare i8* @llvm.coro.begin(token, i8* writeonly) #2
86 declare token @llvm.coro.save(i8*) #2
87 declare i8* @llvm.coro.frame() #3
88 declare i8 @llvm.coro.suspend(token, i1) #2
89 declare i8* @llvm.coro.free(token, i8* nocapture readonly) #1
90 declare i1 @llvm.coro.end(i8*, i1) #2
91 declare i8* @llvm.coro.subfn.addr(i8* nocapture readonly, i8) #1
92 declare i8* @malloc(i64)
93 declare i8 @switch_result()
97 attributes #0 = { "coroutine.presplit"="1" }
98 attributes #1 = { argmemonly nounwind readonly }
99 attributes #2 = { nounwind }
100 attributes #3 = { nounwind readnone }