1 ; Check that we can handle edge splits leading into a landingpad
2 ; RUN: opt < %s -coro-split -S | FileCheck %s
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux-gnu"
7 ; CHECK-LABEL: define internal fastcc void @f.resume(
8 define void @f(i1 %cond) "coroutine.presplit"="1" personality i32 0 {
10 %id = call token @llvm.coro.id(i32 16, i8* null, i8* null, i8* null)
11 %size = tail call i64 @llvm.coro.size.i64()
12 %alloc = call i8* @malloc(i64 %size)
13 %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
14 %sp = call i8 @llvm.coro.suspend(token none, i1 false)
15 switch i8 %sp, label %coro.ret [
21 br i1 %cond, label %invoke1, label %invoke2
24 invoke void @may_throw1()
25 to label %unreach unwind label %pad.with.phi
27 invoke void @may_throw2()
28 to label %unreach unwind label %pad.with.phi
30 ; Verify that we cloned landing pad on every edge and inserted a reload of the spilled value
32 ; CHECK: pad.with.phi.from.invoke2:
33 ; CHECK: %0 = landingpad { i8*, i32 }
34 ; CHECK: catch i8* null
35 ; CHECK: br label %pad.with.phi
37 ; CHECK: pad.with.phi.from.invoke1:
38 ; CHECK: %1 = landingpad { i8*, i32 }
39 ; CHECK: catch i8* null
40 ; CHECK: br label %pad.with.phi
42 ; CHECK: pad.with.phi:
43 ; CHECK: %val = phi i32 [ 0, %pad.with.phi.from.invoke1 ], [ 1, %pad.with.phi.from.invoke2 ]
44 ; CHECK: %lp = phi { i8*, i32 } [ %0, %pad.with.phi.from.invoke2 ], [ %1, %pad.with.phi.from.invoke1 ]
45 ; CHECK: %exn = extractvalue { i8*, i32 } %lp, 0
46 ; CHECK: call i8* @__cxa_begin_catch(i8* %exn)
47 ; CHECK: call void @use_val(i32 %val)
48 ; CHECK: call void @__cxa_end_catch()
49 ; CHECK: call void @free(i8* %vFrame)
53 %val = phi i32 [ 0, %invoke1 ], [ 1, %invoke2 ]
54 %lp = landingpad { i8*, i32 }
56 %exn = extractvalue { i8*, i32 } %lp, 0
57 call i8* @__cxa_begin_catch(i8* %exn)
58 call void @use_val(i32 %val)
59 call void @__cxa_end_catch()
62 cleanup: ; preds = %invoke.cont15, %if.else, %if.then, %ehcleanup21, %init.suspend
63 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
64 call void @free(i8* %mem)
68 call i1 @llvm.coro.end(i8* null, i1 false)
75 ; CHECK-LABEL: define internal fastcc void @g.resume(
76 define void @g(i1 %cond, i32 %x, i32 %y) "coroutine.presplit"="1" personality i32 0 {
78 %id = call token @llvm.coro.id(i32 16, i8* null, i8* null, i8* null)
79 %size = tail call i64 @llvm.coro.size.i64()
80 %alloc = call i8* @malloc(i64 %size)
81 %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
82 %sp = call i8 @llvm.coro.suspend(token none, i1 false)
83 switch i8 %sp, label %coro.ret [
89 br i1 %cond, label %invoke1, label %invoke2
92 invoke void @may_throw1()
93 to label %unreach unwind label %pad.with.phi
95 invoke void @may_throw2()
96 to label %unreach unwind label %pad.with.phi
98 ; Verify that we created cleanuppads on every edge and inserted a reload of the spilled value
100 ; CHECK: pad.with.phi.from.invoke2:
101 ; CHECK: %0 = cleanuppad within none []
102 ; CHECK: %y.reload.addr = getelementptr inbounds %g.Frame, %g.Frame* %FramePtr, i32 0, i32 6
103 ; CHECK: %y.reload = load i32, i32* %y.reload.addr
104 ; CHECK: cleanupret from %0 unwind label %pad.with.phi
106 ; CHECK: pad.with.phi.from.invoke1:
107 ; CHECK: %1 = cleanuppad within none []
108 ; CHECK: %x.reload.addr = getelementptr inbounds %g.Frame, %g.Frame* %FramePtr, i32 0, i32 5
109 ; CHECK: %x.reload = load i32, i32* %x.reload.addr
110 ; CHECK: cleanupret from %1 unwind label %pad.with.phi
112 ; CHECK: pad.with.phi:
113 ; CHECK: %val = phi i32 [ %x.reload, %pad.with.phi.from.invoke1 ], [ %y.reload, %pad.with.phi.from.invoke2 ]
114 ; CHECK: %tok = cleanuppad within none []
115 ; CHECK: call void @use_val(i32 %val)
116 ; CHECK: cleanupret from %tok unwind to caller
119 %val = phi i32 [ %x, %invoke1 ], [ %y, %invoke2 ]
120 %tok = cleanuppad within none []
121 call void @use_val(i32 %val)
122 cleanupret from %tok unwind to caller
124 cleanup: ; preds = %invoke.cont15, %if.else, %if.then, %ehcleanup21, %init.suspend
125 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
126 call void @free(i8* %mem)
130 call i1 @llvm.coro.end(i8* null, i1 false)
137 ; CHECK-LABEL: define internal fastcc void @h.resume(
138 define void @h(i1 %cond, i32 %x, i32 %y) "coroutine.presplit"="1" personality i32 0 {
140 %id = call token @llvm.coro.id(i32 16, i8* null, i8* null, i8* null)
141 %size = tail call i64 @llvm.coro.size.i64()
142 %alloc = call i8* @malloc(i64 %size)
143 %hdl = call i8* @llvm.coro.begin(token %id, i8* %alloc)
144 %sp = call i8 @llvm.coro.suspend(token none, i1 false)
145 switch i8 %sp, label %coro.ret [
151 br i1 %cond, label %invoke1, label %invoke2
154 invoke void @may_throw1()
155 to label %coro.ret unwind label %pad.with.phi
157 invoke void @may_throw2()
158 to label %coro.ret unwind label %pad.with.phi
160 ; Verify that we created cleanuppads on every edge and inserted a reload of the spilled value
162 ; CHECK: pad.with.phi.from.invoke2:
163 ; CHECK: %0 = cleanuppad within none []
164 ; CHECK: %y.reload.addr = getelementptr inbounds %h.Frame, %h.Frame* %FramePtr, i32 0, i32 6
165 ; CHECK: %y.reload = load i32, i32* %y.reload.addr
166 ; CHECK: cleanupret from %0 unwind label %pad.with.phi
168 ; CHECK: pad.with.phi.from.invoke1:
169 ; CHECK: %1 = cleanuppad within none []
170 ; CHECK: %x.reload.addr = getelementptr inbounds %h.Frame, %h.Frame* %FramePtr, i32 0, i32 5
171 ; CHECK: %x.reload = load i32, i32* %x.reload.addr
172 ; CHECK: cleanupret from %1 unwind label %pad.with.phi
174 ; CHECK: pad.with.phi:
175 ; CHECK: %val = phi i32 [ %x.reload, %pad.with.phi.from.invoke1 ], [ %y.reload, %pad.with.phi.from.invoke2 ]
176 ; CHECK: %switch = catchswitch within none [label %catch] unwind to caller
178 %val = phi i32 [ %x, %invoke1 ], [ %y, %invoke2 ]
179 %switch = catchswitch within none [label %catch] unwind to caller
181 catch: ; preds = %catch.dispatch
182 %pad = catchpad within %switch [i8* null, i32 64, i8* null]
183 call void @use_val(i32 %val)
184 catchret from %pad to label %coro.ret
186 cleanup: ; preds = %invoke.cont15, %if.else, %if.then, %ehcleanup21, %init.suspend
187 %mem = call i8* @llvm.coro.free(token %id, i8* %hdl)
188 call void @free(i8* %mem)
192 call i1 @llvm.coro.end(i8* null, i1 false)
196 ; Function Attrs: argmemonly nounwind readonly
197 declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*)
198 declare noalias i8* @malloc(i64)
199 declare i64 @llvm.coro.size.i64()
200 declare i8* @llvm.coro.begin(token, i8* writeonly)
202 ; Function Attrs: nounwind
203 declare token @llvm.coro.save(i8*)
204 declare i8 @llvm.coro.suspend(token, i1)
206 ; Function Attrs: argmemonly nounwind
207 declare void @may_throw1()
208 declare void @may_throw2()
210 declare i8* @__cxa_begin_catch(i8*)
212 declare void @use_val(i32)
213 declare void @__cxa_end_catch()
215 ; Function Attrs: nounwind
216 declare i1 @llvm.coro.end(i8*, i1)
217 declare void @free(i8*)
218 declare i8* @llvm.coro.free(token, i8* nocapture readonly)