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 switch i8 %suspend, label %exit [
18 i8 0, label %await.suspend
22 %save2 = call token @llvm.coro.save(i8* null)
23 %br0 = call i8 @switch_result()
24 switch i8 %br0, label %unreach [
25 i8 0, label %await.resume3
26 i8 1, label %await.resume1
27 i8 2, label %await.resume2
31 %addr2 = call i8* @llvm.coro.subfn.addr(i8* %hdl, i8 0)
32 %pv2 = bitcast i8* %addr2 to void (i8*)*
33 call fastcc void %pv2(i8* %hdl)
34 br label %final.suspend
37 %addr3 = call i8* @llvm.coro.subfn.addr(i8* %hdl2, i8 0)
38 %pv3 = bitcast i8* %addr3 to void (i8*)*
39 call fastcc void %pv3(i8* %hdl2)
40 br label %final.suspend
42 %addr4 = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
43 %pv4 = bitcast i8* %addr4 to void (i8*)*
44 call fastcc void %pv4(i8* null)
45 br label %final.suspend
47 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
48 switch i8 %suspend2, label %exit [
55 call i1 @llvm.coro.end(i8* null, i1 false)
61 ; Verify that in the initial function resume is not marked with musttail.
63 ; CHECK: %[[addr1:.+]] = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
64 ; CHECK-NEXT: %[[pv1:.+]] = bitcast i8* %[[addr1]] to void (i8*)*
65 ; CHECK-NOT: musttail call fastcc void %[[pv1]](i8* null)
67 ; Verify that in the resume part resume call is marked with musttail.
68 ; CHECK-LABEL: @f.resume(
69 ; CHECK: %[[hdl:.+]] = call i8* @g()
70 ; CHECK-NEXT: %[[addr2:.+]] = call i8* @llvm.coro.subfn.addr(i8* %[[hdl]], i8 0)
71 ; CHECK-NEXT: %[[pv2:.+]] = bitcast i8* %[[addr2]] to void (i8*)*
72 ; CHECK-NEXT: musttail call fastcc void %[[pv2]](i8* %[[hdl]])
73 ; CHECK-NEXT: ret void
74 ; CHECK: %[[hdl2:.+]] = call i8* @h()
75 ; CHECK-NEXT: %[[addr3:.+]] = call i8* @llvm.coro.subfn.addr(i8* %[[hdl2]], i8 0)
76 ; CHECK-NEXT: %[[pv3:.+]] = bitcast i8* %[[addr3]] to void (i8*)*
77 ; CHECK-NEXT: musttail call fastcc void %[[pv3]](i8* %[[hdl2]])
78 ; CHECK-NEXT: ret void
79 ; CHECK: %[[addr4:.+]] = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
80 ; CHECK-NEXT: %[[pv4:.+]] = bitcast i8* %[[addr4]] to void (i8*)*
81 ; CHECK-NEXT: musttail call fastcc void %[[pv4]](i8* null)
82 ; CHECK-NEXT: ret void
86 declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*) #1
87 declare i1 @llvm.coro.alloc(token) #2
88 declare i64 @llvm.coro.size.i64() #3
89 declare i8* @llvm.coro.begin(token, i8* writeonly) #2
90 declare token @llvm.coro.save(i8*) #2
91 declare i8* @llvm.coro.frame() #3
92 declare i8 @llvm.coro.suspend(token, i1) #2
93 declare i8* @llvm.coro.free(token, i8* nocapture readonly) #1
94 declare i1 @llvm.coro.end(i8*, i1) #2
95 declare i8* @llvm.coro.subfn.addr(i8* nocapture readonly, i8) #1
96 declare i8* @malloc(i64)
97 declare i8 @switch_result()
101 attributes #0 = { "coroutine.presplit"="1" }
102 attributes #1 = { argmemonly nounwind readonly }
103 attributes #2 = { nounwind }
104 attributes #3 = { nounwind readnone }