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 %cmp = icmp eq i8 %suspend, 0
18 br i1 %cmp, label %await.suspend, label %exit
20 %save2 = call token @llvm.coro.save(ptr 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 ptr @llvm.coro.subfn.addr(ptr %hdl, i8 0)
30 call fastcc void %addr2(ptr %hdl)
31 br label %final.suspend
34 %addr3 = call ptr @llvm.coro.subfn.addr(ptr %hdl2, i8 0)
35 call fastcc void %addr3(ptr %hdl2)
36 br label %final.suspend
38 %addr4 = call ptr @llvm.coro.subfn.addr(ptr null, i8 0)
39 call fastcc void %addr4(ptr null)
40 br label %final.suspend
42 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
43 %cmp2 = icmp eq i8 %suspend2, 0
44 br i1 %cmp2, label %pre.exit, label %exit
48 call i1 @llvm.coro.end(ptr null, i1 false, token none)
54 ; Verify that in the initial function resume is not marked with musttail.
56 ; CHECK: %[[addr1:.+]] = call ptr @llvm.coro.subfn.addr(ptr null, i8 0)
57 ; CHECK-NOT: musttail call fastcc void %[[addr1]](ptr null)
59 ; Verify that in the resume part resume call is marked with musttail.
60 ; CHECK-LABEL: @f.resume(
61 ; CHECK: %[[hdl:.+]] = call ptr @g()
62 ; CHECK-NEXT: %[[addr2:.+]] = call ptr @llvm.coro.subfn.addr(ptr %[[hdl]], i8 0)
63 ; NOPGO-NEXT: musttail call fastcc void %[[addr2]](ptr %[[hdl]])
64 ; PGO: musttail call fastcc void %[[addr2]](ptr %[[hdl]])
65 ; CHECK-NEXT: ret void
66 ; CHECK: %[[hdl2:.+]] = call ptr @h()
67 ; CHECK-NEXT: %[[addr3:.+]] = call ptr @llvm.coro.subfn.addr(ptr %[[hdl2]], i8 0)
68 ; NOPGO-NEXT: musttail call fastcc void %[[addr3]](ptr %[[hdl2]])
69 ; PGO: musttail call fastcc void %[[addr3]](ptr %[[hdl2]])
70 ; CHECK-NEXT: ret void
71 ; CHECK: %[[addr4:.+]] = call ptr @llvm.coro.subfn.addr(ptr null, i8 0)
72 ; NOPGO-NEXT: musttail call fastcc void %[[addr4]](ptr null)
73 ; PGO: musttail call fastcc void %[[addr4]](ptr null)
74 ; CHECK-NEXT: ret void
78 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
79 declare i1 @llvm.coro.alloc(token) #2
80 declare i64 @llvm.coro.size.i64() #3
81 declare ptr @llvm.coro.begin(token, ptr writeonly) #2
82 declare token @llvm.coro.save(ptr) #2
83 declare ptr @llvm.coro.frame() #3
84 declare i8 @llvm.coro.suspend(token, i1) #2
85 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1
86 declare i1 @llvm.coro.end(ptr, i1, token) #2
87 declare ptr @llvm.coro.subfn.addr(ptr nocapture readonly, i8) #1
88 declare ptr @malloc(i64)
89 declare i8 @switch_result()
93 attributes #0 = { presplitcoroutine }
94 attributes #1 = { argmemonly nounwind readonly }
95 attributes #2 = { nounwind }
96 attributes #3 = { nounwind readnone }