1 ; Tests that sinked lifetime markers wouldn't provent optimization
2 ; to convert a resuming call to a musttail call.
3 ; The difference between this and coro-split-musttail5.ll and coro-split-musttail5.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
9 declare void @fakeresume1(ptr align 8)
13 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
14 %alloc = call ptr @malloc(i64 16) #3
15 %alloc.var = alloca i64
16 call void @llvm.lifetime.start.p0(i64 1, ptr %alloc.var)
17 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
19 %save = call token @llvm.coro.save(ptr null)
20 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
22 switch i8 %suspend, label %exit [
23 i8 0, label %await.suspend
27 %save2 = call token @llvm.coro.save(ptr null)
28 call fastcc void @fakeresume1(ptr align 8 null)
29 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
30 switch i8 %suspend2, label %exit [
31 i8 0, label %await.ready
35 call void @consume(ptr %alloc.var)
36 call void @llvm.lifetime.end.p0(i64 1, ptr %alloc.var)
39 call i1 @llvm.coro.end(ptr null, i1 false, token none)
43 ; Verify that in the resume part resume call is marked with musttail.
44 ; CHECK-LABEL: @g.resume(
45 ; CHECK: musttail call fastcc void @fakeresume1(ptr align 8 null)
46 ; CHECK-NEXT: ret void
48 ; It has a cleanup bb.
51 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
52 %alloc = call ptr @malloc(i64 16) #3
53 %alloc.var = alloca i64
54 call void @llvm.lifetime.start.p0(i64 1, ptr %alloc.var)
55 %vFrame = call noalias nonnull ptr @llvm.coro.begin(token %id, ptr %alloc)
57 %save = call token @llvm.coro.save(ptr null)
58 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
60 switch i8 %suspend, label %exit [
61 i8 0, label %await.suspend
65 %save2 = call token @llvm.coro.save(ptr null)
66 call fastcc void @fakeresume1(ptr align 8 null)
67 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
68 switch i8 %suspend2, label %exit [
69 i8 0, label %await.ready
73 call void @consume(ptr %alloc.var)
74 call void @llvm.lifetime.end.p0(i64 1, ptr %alloc.var)
78 %free.handle = call ptr @llvm.coro.free(token %id, ptr %vFrame)
79 %.not = icmp eq ptr %free.handle, null
80 br i1 %.not, label %exit, label %coro.free
83 call void @delete(ptr nonnull %free.handle) #2
87 call i1 @llvm.coro.end(ptr null, i1 false, token none)
91 ; FIXME: The fakeresume1 here should be marked as musttail.
92 ; Verify that in the resume part resume call is marked with musttail.
93 ; CHECK-LABEL: @f.resume(
94 ; CHECK: musttail call fastcc void @fakeresume1(ptr align 8 null)
95 ; CHECK-NEXT: ret void
97 declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1
98 declare i1 @llvm.coro.alloc(token) #2
99 declare i64 @llvm.coro.size.i64() #3
100 declare ptr @llvm.coro.begin(token, ptr writeonly) #2
101 declare token @llvm.coro.save(ptr) #2
102 declare ptr @llvm.coro.frame() #3
103 declare i8 @llvm.coro.suspend(token, i1) #2
104 declare ptr @llvm.coro.free(token, ptr nocapture readonly) #1
105 declare i1 @llvm.coro.end(ptr, i1, token) #2
106 declare ptr @llvm.coro.subfn.addr(ptr nocapture readonly, i8) #1
107 declare ptr @malloc(i64)
108 declare void @delete(ptr nonnull) #2
109 declare void @consume(ptr)
110 declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
111 declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
113 attributes #0 = { presplitcoroutine }
114 attributes #1 = { argmemonly nounwind readonly }
115 attributes #2 = { nounwind }
116 attributes #3 = { nounwind readnone }