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 is that there is
4 ; an extra bitcast instruction in the path, which makes it harder to
6 ; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
8 declare void @fakeresume1(i64* align 8)
12 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
13 %alloc = call i8* @malloc(i64 16) #3
14 %alloc.var = alloca i64
15 %alloca.var.i8 = bitcast i64* %alloc.var to i8*
16 call void @llvm.lifetime.start.p0i8(i64 1, i8* %alloca.var.i8)
17 %vFrame = call noalias nonnull i8* @llvm.coro.begin(token %id, i8* %alloc)
19 %save = call token @llvm.coro.save(i8* 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(i8* null)
28 call fastcc void @fakeresume1(i64* 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(i64* %alloc.var)
36 call void @llvm.lifetime.end.p0i8(i64 1, i8* %alloca.var.i8)
39 call i1 @llvm.coro.end(i8* null, i1 false)
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(i64* align 8 null)
46 ; CHECK-NEXT: ret void
48 ; It has a cleanup bb.
51 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
52 %alloc = call i8* @malloc(i64 16) #3
53 %alloc.var = alloca i64
54 %alloca.var.i8 = bitcast i64* %alloc.var to i8*
55 call void @llvm.lifetime.start.p0i8(i64 1, i8* %alloca.var.i8)
56 %vFrame = call noalias nonnull i8* @llvm.coro.begin(token %id, i8* %alloc)
58 %save = call token @llvm.coro.save(i8* null)
59 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
61 switch i8 %suspend, label %exit [
62 i8 0, label %await.suspend
66 %save2 = call token @llvm.coro.save(i8* null)
67 call fastcc void @fakeresume1(i64* align 8 null)
68 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
69 switch i8 %suspend2, label %exit [
70 i8 0, label %await.ready
74 call void @consume(i64* %alloc.var)
75 call void @llvm.lifetime.end.p0i8(i64 1, i8* %alloca.var.i8)
79 %free.handle = call i8* @llvm.coro.free(token %id, i8* %vFrame)
80 %.not = icmp eq i8* %free.handle, null
81 br i1 %.not, label %exit, label %coro.free
84 call void @delete(i8* nonnull %free.handle) #2
88 call i1 @llvm.coro.end(i8* null, i1 false)
92 ; FIXME: The fakeresume1 here should be marked as musttail.
93 ; Verify that in the resume part resume call is marked with musttail.
94 ; CHECK-LABEL: @f.resume(
95 ; CHECK: musttail call fastcc void @fakeresume1(i64* align 8 null)
96 ; CHECK-NEXT: ret void
98 declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*) #1
99 declare i1 @llvm.coro.alloc(token) #2
100 declare i64 @llvm.coro.size.i64() #3
101 declare i8* @llvm.coro.begin(token, i8* writeonly) #2
102 declare token @llvm.coro.save(i8*) #2
103 declare i8* @llvm.coro.frame() #3
104 declare i8 @llvm.coro.suspend(token, i1) #2
105 declare i8* @llvm.coro.free(token, i8* nocapture readonly) #1
106 declare i1 @llvm.coro.end(i8*, i1) #2
107 declare i8* @llvm.coro.subfn.addr(i8* nocapture readonly, i8) #1
108 declare i8* @malloc(i64)
109 declare void @delete(i8* nonnull) #2
110 declare void @consume(i64*)
111 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
112 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
114 attributes #0 = { presplitcoroutine }
115 attributes #1 = { argmemonly nounwind readonly }
116 attributes #2 = { nounwind }
117 attributes #3 = { nounwind readnone }