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 %s
3 ; RUN: opt < %s -passes='pgo-instr-gen,cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
5 define void @fakeresume1(ptr) {
12 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
13 %alloc = call ptr @malloc(i64 16) #3
14 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
16 %save = call token @llvm.coro.save(ptr null)
17 call fastcc void @fakeresume1(ptr null)
19 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
20 switch i8 %suspend, label %exit [
21 i8 0, label %await.ready
25 %save2 = call token @llvm.coro.save(ptr null)
26 call void @llvm.coro.await.suspend.handle(ptr null, ptr null, ptr @await_suspend_function)
28 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
29 switch i8 %suspend2, label %exit [
34 call i1 @llvm.coro.end(ptr null, i1 false, token none)
38 ; Verify that in the initial function resume is not marked with musttail.
40 ; CHECK-NOT: musttail call fastcc void @fakeresume1(ptr null)
42 ; Verify that in the resume part resume call is marked with musttail.
43 ; CHECK-LABEL: @g.resume(
44 ; CHECK: call ptr @await_suspend_function
45 ; CHECK-NEXT: call ptr @llvm.coro.subfn.addr
46 ; CHECK-NEXT: musttail call fastcc void
47 ; CHECK-NEXT: ret void
49 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
50 declare i1 @llvm.coro.alloc(token) #2
51 declare i64 @llvm.coro.size.i64() #3
52 declare ptr @llvm.coro.begin(token, ptr writeonly) #2
53 declare token @llvm.coro.save(ptr) #2
54 declare ptr @llvm.coro.frame() #3
55 declare i8 @llvm.coro.suspend(token, i1) #2
56 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1
57 declare i1 @llvm.coro.end(ptr, i1, token) #2
58 declare ptr @llvm.coro.subfn.addr(ptr nocapture readonly, i8) #1
59 declare ptr @malloc(i64)
60 declare ptr @await_suspend_function(ptr %awaiter, ptr %hdl)
62 attributes #0 = { presplitcoroutine }
63 attributes #1 = { argmemonly nounwind readonly }
64 attributes #2 = { nounwind }
65 attributes #3 = { nounwind readnone }