1 ; Tests that sinked lifetime markers wouldn't provent optimization
2 ; to convert a coro.await.suspend.handle call to a musttail call.
3 ; The difference between this and coro-split-musttail5.ll and coro-split-musttail6.ll
4 ; is that this contains dead instruction generated during the transformation,
5 ; which makes the optimization harder.
6 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
7 ; RUN: opt < %s -passes='pgo-instr-gen,cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
11 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
12 %alloc = call ptr @malloc(i64 16) #3
13 %alloc.var = alloca i64
14 call void @llvm.lifetime.start.p0(i64 1, ptr %alloc.var)
15 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
17 %save = call token @llvm.coro.save(ptr null)
18 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
20 switch i8 %suspend, label %exit [
21 i8 0, label %await.suspend
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)
27 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
29 ; These (non-trivially) dead instructions are in the way.
30 %gep = getelementptr inbounds i64, ptr %alloc.var, i32 0
31 %foo = ptrtoint ptr %gep to i64
33 switch i8 %suspend2, label %exit [
34 i8 0, label %await.ready
38 call void @consume(ptr %alloc.var)
39 call void @llvm.lifetime.end.p0(i64 1, ptr %alloc.var)
42 %result = phi i64 [0, %entry], [0, %entry], [%foo, %await.suspend], [%foo, %await.suspend], [%foo, %await.ready]
43 call i1 @llvm.coro.end(ptr null, i1 false, token none)
47 ; Verify that in the resume part resume call is marked with musttail.
48 ; CHECK-LABEL: @g.resume(
49 ; CHECK: %[[FRAME:[0-9]+]] = call ptr @await_suspend_function(ptr null, ptr null)
50 ; CHECK: %[[RESUMEADDR:[0-9]+]] = call ptr @llvm.coro.subfn.addr(ptr %[[FRAME]], i8 0)
51 ; CHECK: musttail call fastcc void %[[RESUMEADDR]](ptr %[[FRAME]])
52 ; CHECK-NEXT: ret void
54 ; It has a cleanup bb.
57 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
58 %alloc = call ptr @malloc(i64 16) #3
59 %alloc.var = alloca i64
60 call void @llvm.lifetime.start.p0(i64 1, ptr %alloc.var)
61 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
63 %save = call token @llvm.coro.save(ptr null)
64 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
66 switch i8 %suspend, label %exit [
67 i8 0, label %await.suspend
71 %save2 = call token @llvm.coro.save(ptr null)
72 call void @llvm.coro.await.suspend.handle(ptr null, ptr null, ptr @await_suspend_function)
73 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
74 switch i8 %suspend2, label %exit [
75 i8 0, label %await.ready
79 call void @consume(ptr %alloc.var)
80 call void @llvm.lifetime.end.p0(i64 1, ptr %alloc.var)
84 %free.handle = call ptr @llvm.coro.free(token %id, ptr %vFrame)
85 %.not = icmp eq ptr %free.handle, null
86 br i1 %.not, label %exit, label %coro.free
89 call void @delete(ptr nonnull %free.handle) #2
93 call i1 @llvm.coro.end(ptr null, i1 false, token none)
97 ; Verify that in the resume part resume call is marked with musttail.
98 ; CHECK-LABEL: @f.resume(
99 ; CHECK: %[[FRAME:[0-9]+]] = call ptr @await_suspend_function(ptr null, ptr null)
100 ; CHECK: %[[RESUMEADDR:[0-9]+]] = call ptr @llvm.coro.subfn.addr(ptr %[[FRAME]], i8 0)
101 ; CHECK: musttail call fastcc void %[[RESUMEADDR]](ptr %[[FRAME]])
102 ; CHECK-NEXT: ret void
104 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
105 declare i1 @llvm.coro.alloc(token) #2
106 declare i64 @llvm.coro.size.i64() #3
107 declare ptr @llvm.coro.begin(token, ptr writeonly) #2
108 declare token @llvm.coro.save(ptr) #2
109 declare ptr @llvm.coro.frame() #3
110 declare i8 @llvm.coro.suspend(token, i1) #2
111 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1
112 declare i1 @llvm.coro.end(ptr, i1, token) #2
113 declare ptr @llvm.coro.subfn.addr(ptr nocapture readonly, i8) #1
114 declare ptr @malloc(i64)
115 declare void @delete(ptr nonnull) #2
116 declare void @consume(ptr)
117 declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
118 declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
119 declare ptr @await_suspend_function(ptr %awaiter, ptr %hdl)
121 attributes #0 = { presplitcoroutine }
122 attributes #1 = { argmemonly nounwind readonly }
123 attributes #2 = { nounwind }
124 attributes #3 = { nounwind readnone }