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 declare void @fakeresume1(ptr align 8)
9 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
10 %alloc = call ptr @malloc(i64 16) #3
11 %alloc.var = alloca i8
12 call void @llvm.lifetime.start.p0(i64 1, ptr %alloc.var)
13 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
15 %save = call token @llvm.coro.save(ptr null)
16 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
18 switch i8 %suspend, label %exit [
19 i8 0, label %await.suspend
23 %save2 = call token @llvm.coro.save(ptr null)
24 call void @llvm.coro.await.suspend.handle(ptr null, ptr null, ptr @await_suspend_function)
25 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
26 switch i8 %suspend2, label %exit [
27 i8 0, label %await.ready
31 call void @consume(ptr %alloc.var)
32 call void @llvm.lifetime.end.p0(i64 1, ptr %alloc.var)
35 call i1 @llvm.coro.end(ptr null, i1 false, token none)
39 ; Verify that in the resume part resume call is marked with musttail.
40 ; CHECK-LABEL: @g.resume(
41 ; CHECK: musttail call fastcc void
42 ; CHECK-NEXT: ret void
44 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
45 declare i1 @llvm.coro.alloc(token) #2
46 declare i64 @llvm.coro.size.i64() #3
47 declare ptr @llvm.coro.begin(token, ptr writeonly) #2
48 declare token @llvm.coro.save(ptr) #2
49 declare ptr @llvm.coro.frame() #3
50 declare i8 @llvm.coro.suspend(token, i1) #2
51 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1
52 declare i1 @llvm.coro.end(ptr, i1, token) #2
53 declare ptr @llvm.coro.subfn.addr(ptr nocapture readonly, i8) #1
54 declare ptr @malloc(i64)
55 declare void @consume(ptr)
56 declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
57 declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
58 declare ptr @await_suspend_function(ptr %awaiter, ptr %hdl)
60 attributes #0 = { presplitcoroutine }
61 attributes #1 = { argmemonly nounwind readonly }
62 attributes #2 = { nounwind }
63 attributes #3 = { nounwind readnone }