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 --check-prefixes=CHECK,NOPGO %s
4 ; RUN: opt < %s -passes='pgo-instr-gen,cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck --check-prefixes=CHECK,PGO %s
8 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
9 %alloc = call ptr @malloc(i64 16) #3
10 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
12 %save = call token @llvm.coro.save(ptr null)
13 %addr1 = call ptr @llvm.coro.subfn.addr(ptr null, i8 0)
14 call fastcc void %addr1(ptr 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(ptr 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 ptr @llvm.coro.subfn.addr(ptr %hdl, i8 0)
32 call fastcc void %addr2(ptr %hdl)
33 br label %final.suspend
36 %addr3 = call ptr @llvm.coro.subfn.addr(ptr %hdl2, i8 0)
37 call fastcc void %addr3(ptr %hdl2)
38 br label %final.suspend
40 %addr4 = call ptr @llvm.coro.subfn.addr(ptr null, i8 0)
41 call fastcc void %addr4(ptr null)
42 br label %final.suspend
44 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
45 switch i8 %suspend2, label %exit [
52 call i1 @llvm.coro.end(ptr null, i1 false, token none)
58 ; Verify that in the initial function resume is not marked with musttail.
60 ; CHECK: %[[addr1:.+]] = call ptr @llvm.coro.subfn.addr(ptr null, i8 0)
61 ; CHECK-NOT: musttail call fastcc void %[[addr1]](ptr null)
63 ; Verify that in the resume part resume call is marked with musttail.
64 ; CHECK-LABEL: @f.resume(
65 ; CHECK: %[[hdl:.+]] = call ptr @g()
66 ; CHECK-NEXT: %[[addr2:.+]] = call ptr @llvm.coro.subfn.addr(ptr %[[hdl]], i8 0)
67 ; NOPGO-NEXT: musttail call fastcc void %[[addr2]](ptr %[[hdl]])
68 ; PGO: musttail call fastcc void %[[addr2]](ptr %[[hdl]])
69 ; CHECK-NEXT: ret void
70 ; CHECK: %[[hdl2:.+]] = call ptr @h()
71 ; CHECK-NEXT: %[[addr3:.+]] = call ptr @llvm.coro.subfn.addr(ptr %[[hdl2]], i8 0)
72 ; NOPGO-NEXT: musttail call fastcc void %[[addr3]](ptr %[[hdl2]])
73 ; PGO: musttail call fastcc void %[[addr3]](ptr %[[hdl2]])
74 ; CHECK-NEXT: ret void
75 ; CHECK: %[[addr4:.+]] = call ptr @llvm.coro.subfn.addr(ptr null, i8 0)
76 ; NOPGO-NEXT: musttail call fastcc void %[[addr4]](ptr null)
77 ; PGO: musttail call fastcc void %[[addr4]](ptr null)
78 ; CHECK-NEXT: ret void
82 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
83 declare i1 @llvm.coro.alloc(token) #2
84 declare i64 @llvm.coro.size.i64() #3
85 declare ptr @llvm.coro.begin(token, ptr writeonly) #2
86 declare token @llvm.coro.save(ptr) #2
87 declare ptr @llvm.coro.frame() #3
88 declare i8 @llvm.coro.suspend(token, i1) #2
89 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1
90 declare i1 @llvm.coro.end(ptr, i1, token) #2
91 declare ptr @llvm.coro.subfn.addr(ptr nocapture readonly, i8) #1
92 declare ptr @malloc(i64)
93 declare i8 @switch_result()
97 attributes #0 = { presplitcoroutine }
98 attributes #1 = { argmemonly nounwind readonly }
99 attributes #2 = { nounwind }
100 attributes #3 = { nounwind readnone }