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
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 %.unused = getelementptr inbounds i8, i8* %vFrame, i32 0
40 call i1 @llvm.coro.end(i8* null, i1 false)
44 ; Verify that in the resume part resume call is marked with musttail.
45 ; CHECK-LABEL: @g.resume(
46 ; CHECK: musttail call fastcc void @fakeresume1(i64* align 8 null)
47 ; CHECK-NEXT: ret void
49 ; It has a cleanup bb.
52 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
53 %alloc = call i8* @malloc(i64 16) #3
54 %alloc.var = alloca i64
55 %alloca.var.i8 = bitcast i64* %alloc.var to i8*
56 call void @llvm.lifetime.start.p0i8(i64 1, i8* %alloca.var.i8)
57 %vFrame = call noalias nonnull i8* @llvm.coro.begin(token %id, i8* %alloc)
59 %save = call token @llvm.coro.save(i8* null)
60 %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
62 switch i8 %suspend, label %exit [
63 i8 0, label %await.suspend
67 %save2 = call token @llvm.coro.save(i8* null)
68 call fastcc void @fakeresume1(i64* align 8 null)
69 %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
70 switch i8 %suspend2, label %exit [
71 i8 0, label %await.ready
75 call void @consume(i64* %alloc.var)
76 call void @llvm.lifetime.end.p0i8(i64 1, i8* %alloca.var.i8)
80 %free.handle = call i8* @llvm.coro.free(token %id, i8* %vFrame)
81 %.not = icmp eq i8* %free.handle, null
82 br i1 %.not, label %exit, label %coro.free
85 call void @delete(i8* nonnull %free.handle) #2
89 %.unused = getelementptr inbounds i8, i8* %vFrame, i32 0
90 call i1 @llvm.coro.end(i8* null, i1 false)
94 ; FIXME: The fakeresume1 here should be marked as musttail.
95 ; Verify that in the resume part resume call is marked with musttail.
96 ; CHECK-LABEL: @f.resume(
97 ; CHECK: musttail call fastcc void @fakeresume1(i64* align 8 null)
98 ; CHECK-NEXT: ret void
100 declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*) #1
101 declare i1 @llvm.coro.alloc(token) #2
102 declare i64 @llvm.coro.size.i64() #3
103 declare i8* @llvm.coro.begin(token, i8* writeonly) #2
104 declare token @llvm.coro.save(i8*) #2
105 declare i8* @llvm.coro.frame() #3
106 declare i8 @llvm.coro.suspend(token, i1) #2
107 declare i8* @llvm.coro.free(token, i8* nocapture readonly) #1
108 declare i1 @llvm.coro.end(i8*, i1) #2
109 declare i8* @llvm.coro.subfn.addr(i8* nocapture readonly, i8) #1
110 declare i8* @malloc(i64)
111 declare void @delete(i8* nonnull) #2
112 declare void @consume(i64*)
113 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
114 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
116 attributes #0 = { presplitcoroutine }
117 attributes #1 = { argmemonly nounwind readonly }
118 attributes #2 = { nounwind }
119 attributes #3 = { nounwind readnone }