1 ; RUN: opt < %s -inline -S | FileCheck %s
2 ; RUN: opt < %s -passes='cgscc(inline)' -S | FileCheck %s
4 ; Test that the inliner correctly handles inlining into invoke sites
5 ; by appending selectors and forwarding _Unwind_Resume directly to the
6 ; enclosing landing pad.
8 ;; Test 0 - basic functionality.
10 %struct.A = type { i8 }
12 @_ZTIi = external constant i8*
14 declare void @_ZN1AC1Ev(%struct.A*)
16 declare void @_ZN1AD1Ev(%struct.A*)
18 declare void @use(i32) nounwind
20 declare void @opaque()
22 declare i32 @llvm.eh.typeid.for(i8*) nounwind
24 declare i32 @__gxx_personality_v0(...)
26 declare i8* @__cxa_begin_catch(i8*)
28 declare void @__cxa_end_catch()
30 declare void @_ZSt9terminatev()
32 define internal void @test0_in() alwaysinline uwtable ssp personality i32 (...)* @__gxx_personality_v0 {
34 %a = alloca %struct.A, align 1
35 %b = alloca %struct.A, align 1
36 call void @_ZN1AC1Ev(%struct.A* %a)
37 invoke void @_ZN1AC1Ev(%struct.A* %b)
38 to label %invoke.cont unwind label %lpad
41 invoke void @_ZN1AD1Ev(%struct.A* %b)
42 to label %invoke.cont1 unwind label %lpad
45 call void @_ZN1AD1Ev(%struct.A* %a)
49 %exn = landingpad {i8*, i32}
51 invoke void @_ZN1AD1Ev(%struct.A* %a)
52 to label %invoke.cont2 unwind label %terminate.lpad
55 resume { i8*, i32 } %exn
58 %exn1 = landingpad {i8*, i32}
60 call void @_ZSt9terminatev() noreturn nounwind
64 define void @test0_out() uwtable ssp personality i32 (...)* @__gxx_personality_v0 {
66 invoke void @test0_in()
67 to label %ret unwind label %lpad
72 lpad: ; preds = %entry
73 %exn = landingpad {i8*, i32}
74 catch i8* bitcast (i8** @_ZTIi to i8*)
75 %eh.exc = extractvalue { i8*, i32 } %exn, 0
76 %eh.selector = extractvalue { i8*, i32 } %exn, 1
77 %0 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind
78 %1 = icmp eq i32 %eh.selector, %0
79 br i1 %1, label %catch, label %eh.resume
82 %ignored = call i8* @__cxa_begin_catch(i8* %eh.exc) nounwind
83 call void @__cxa_end_catch() nounwind
87 resume { i8*, i32 } %exn
90 ; CHECK: define void @test0_out()
91 ; CHECK: [[A:%.*]] = alloca %struct.A,
92 ; CHECK: [[B:%.*]] = alloca %struct.A,
93 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A]])
94 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B]])
95 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B]])
96 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
97 ; CHECK: landingpad { i8*, i32 }
99 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
100 ; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
101 ; CHECK-NEXT: to label %[[LBL:[^\s]+]] unwind
103 ; CHECK-NEXT: br label %[[LPAD:[^\s]+]]
105 ; CHECK: landingpad { i8*, i32 }
106 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
107 ; CHECK-NEXT: br label %[[LPAD]]
109 ; CHECK-NEXT: phi { i8*, i32 } [
110 ; CHECK-NEXT: extractvalue { i8*, i32 }
111 ; CHECK-NEXT: extractvalue { i8*, i32 }
112 ; CHECK-NEXT: call i32 @llvm.eh.typeid.for(
115 ;; Test 1 - Correctly handle phis in outer landing pads.
117 define void @test1_out() uwtable ssp personality i32 (...)* @__gxx_personality_v0 {
119 invoke void @test0_in()
120 to label %cont unwind label %lpad
123 invoke void @test0_in()
124 to label %ret unwind label %lpad
130 %x = phi i32 [ 0, %entry ], [ 1, %cont ]
131 %y = phi i32 [ 1, %entry ], [ 4, %cont ]
132 %exn = landingpad {i8*, i32}
133 catch i8* bitcast (i8** @_ZTIi to i8*)
134 %eh.exc = extractvalue { i8*, i32 } %exn, 0
135 %eh.selector = extractvalue { i8*, i32 } %exn, 1
136 %0 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind
137 %1 = icmp eq i32 %eh.selector, %0
138 br i1 %1, label %catch, label %eh.resume
141 %ignored = call i8* @__cxa_begin_catch(i8* %eh.exc) nounwind
142 call void @use(i32 %x)
143 call void @use(i32 %y)
144 call void @__cxa_end_catch() nounwind
148 resume { i8*, i32 } %exn
151 ; CHECK: define void @test1_out()
152 ; CHECK: [[A2:%.*]] = alloca %struct.A,
153 ; CHECK: [[B2:%.*]] = alloca %struct.A,
154 ; CHECK: [[A1:%.*]] = alloca %struct.A,
155 ; CHECK: [[B1:%.*]] = alloca %struct.A,
156 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A1]])
157 ; CHECK-NEXT: unwind label %[[LPAD:[^\s]+]]
158 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B1]])
159 ; CHECK-NEXT: unwind label %[[LPAD1:[^\s]+]]
160 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B1]])
161 ; CHECK-NEXT: unwind label %[[LPAD1]]
162 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A1]])
163 ; CHECK-NEXT: unwind label %[[LPAD]]
165 ; Inner landing pad from first inlining.
167 ; CHECK-NEXT: [[LPADVAL1:%.*]] = landingpad { i8*, i32 }
168 ; CHECK-NEXT: cleanup
169 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
170 ; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A1]])
171 ; CHECK-NEXT: to label %[[RESUME1:[^\s]+]] unwind
172 ; CHECK: [[RESUME1]]:
173 ; CHECK-NEXT: br label %[[LPAD_JOIN1:[^\s]+]]
175 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A2]])
176 ; CHECK-NEXT: unwind label %[[LPAD]]
177 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B2]])
178 ; CHECK-NEXT: unwind label %[[LPAD2:[^\s]+]]
179 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B2]])
180 ; CHECK-NEXT: unwind label %[[LPAD2]]
181 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A2]])
182 ; CHECK-NEXT: unwind label %[[LPAD]]
184 ; Inner landing pad from second inlining.
186 ; CHECK-NEXT: [[LPADVAL2:%.*]] = landingpad { i8*, i32 }
187 ; CHECK-NEXT: cleanup
188 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
189 ; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A2]])
190 ; CHECK-NEXT: to label %[[RESUME2:[^\s]+]] unwind
191 ; CHECK: [[RESUME2]]:
192 ; CHECK-NEXT: br label %[[LPAD_JOIN2:[^\s]+]]
197 ; CHECK-NEXT: [[X:%.*]] = phi i32 [ 0, %entry ], [ 0, {{%.*}} ], [ 1, %cont ], [ 1, {{%.*}} ]
198 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ 1, %entry ], [ 1, {{%.*}} ], [ 4, %cont ], [ 4, {{%.*}} ]
199 ; CHECK-NEXT: [[LPADVAL:%.*]] = landingpad { i8*, i32 }
200 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
201 ; CHECK-NEXT: br label %[[LPAD_JOIN2]]
203 ; CHECK: [[LPAD_JOIN2]]:
204 ; CHECK-NEXT: [[XJ2:%.*]] = phi i32 [ [[X]], %[[LPAD]] ], [ 1, %[[RESUME2]] ]
205 ; CHECK-NEXT: [[YJ2:%.*]] = phi i32 [ [[Y]], %[[LPAD]] ], [ 4, %[[RESUME2]] ]
206 ; CHECK-NEXT: [[EXNJ2:%.*]] = phi { i8*, i32 } [ [[LPADVAL]], %[[LPAD]] ], [ [[LPADVAL2]], %[[RESUME2]] ]
207 ; CHECK-NEXT: br label %[[LPAD_JOIN1]]
209 ; CHECK: [[LPAD_JOIN1]]:
210 ; CHECK-NEXT: [[XJ1:%.*]] = phi i32 [ [[XJ2]], %[[LPAD_JOIN2]] ], [ 0, %[[RESUME1]] ]
211 ; CHECK-NEXT: [[YJ1:%.*]] = phi i32 [ [[YJ2]], %[[LPAD_JOIN2]] ], [ 1, %[[RESUME1]] ]
212 ; CHECK-NEXT: [[EXNJ1:%.*]] = phi { i8*, i32 } [ [[EXNJ2]], %[[LPAD_JOIN2]] ], [ [[LPADVAL1]], %[[RESUME1]] ]
213 ; CHECK-NEXT: extractvalue { i8*, i32 } [[EXNJ1]], 0
214 ; CHECK-NEXT: [[SELJ1:%.*]] = extractvalue { i8*, i32 } [[EXNJ1]], 1
215 ; CHECK-NEXT: [[T:%.*]] = call i32 @llvm.eh.typeid.for(
216 ; CHECK-NEXT: icmp eq i32 [[SELJ1]], [[T]]
218 ; CHECK: call void @use(i32 [[XJ1]])
219 ; CHECK: call void @use(i32 [[YJ1]])
221 ; CHECK: resume { i8*, i32 }
224 ;; Test 2 - Don't make invalid IR for inlines into landing pads without eh.exception calls
225 define void @test2_out() uwtable ssp personality i32 (...)* @__gxx_personality_v0 {
227 invoke void @test0_in()
228 to label %ret unwind label %lpad
234 %exn = landingpad {i8*, i32}
236 call void @_ZSt9terminatev()
240 ; CHECK: define void @test2_out()
241 ; CHECK: [[A:%.*]] = alloca %struct.A,
242 ; CHECK: [[B:%.*]] = alloca %struct.A,
243 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A]])
244 ; CHECK-NEXT: unwind label %[[LPAD:[^\s]+]]
245 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B]])
246 ; CHECK-NEXT: unwind label %[[LPAD2:[^\s]+]]
247 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B]])
248 ; CHECK-NEXT: unwind label %[[LPAD2]]
249 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
250 ; CHECK-NEXT: unwind label %[[LPAD]]
253 ;; Test 3 - Deal correctly with split unwind edges.
254 define void @test3_out() uwtable ssp personality i32 (...)* @__gxx_personality_v0 {
256 invoke void @test0_in()
257 to label %ret unwind label %lpad
263 %exn = landingpad {i8*, i32}
264 catch i8* bitcast (i8** @_ZTIi to i8*)
268 call void @_ZSt9terminatev()
272 ; CHECK: define void @test3_out()
273 ; CHECK: landingpad { i8*, i32 }
274 ; CHECK-NEXT: cleanup
275 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
276 ; CHECK-NEXT: invoke void @_ZN1AD1Ev(
277 ; CHECK-NEXT: to label %[[L:[^\s]+]] unwind
279 ; CHECK-NEXT: br label %[[JOIN:[^\s]+]]
281 ; CHECK-NEXT: phi { i8*, i32 }
282 ; CHECK-NEXT: br label %lpad.cont
284 ; CHECK-NEXT: call void @_ZSt9terminatev()
287 ;; Test 4 - Split unwind edges with a dominance problem
288 define void @test4_out() uwtable ssp personality i32 (...)* @__gxx_personality_v0 {
290 invoke void @test0_in()
291 to label %cont unwind label %lpad.crit
294 invoke void @opaque()
295 to label %ret unwind label %lpad
301 %exn = landingpad {i8*, i32}
302 catch i8* bitcast (i8** @_ZTIi to i8*)
303 call void @opaque() nounwind
307 %exn2 = landingpad {i8*, i32}
308 catch i8* bitcast (i8** @_ZTIi to i8*)
312 %phi = phi i32 [ 0, %lpad.crit ], [ 1, %lpad ]
313 call void @use(i32 %phi)
314 call void @_ZSt9terminatev()
318 ; CHECK: define void @test4_out()
319 ; CHECK: landingpad { i8*, i32 }
320 ; CHECK-NEXT: cleanup
321 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
322 ; CHECK-NEXT: invoke void @_ZN1AD1Ev(
323 ; CHECK-NEXT: to label %[[L:[^\s]+]] unwind
325 ; CHECK-NEXT: br label %[[JOIN:[^\s]+]]
326 ; CHECK: invoke void @opaque()
327 ; CHECK-NEXT: unwind label %lpad
329 ; CHECK-NEXT: landingpad { i8*, i32 }
330 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
331 ; CHECK-NEXT: br label %[[JOIN]]
333 ; CHECK-NEXT: phi { i8*, i32 }
334 ; CHECK-NEXT: call void @opaque() [[NUW:#[0-9]+]]
335 ; CHECK-NEXT: br label %[[FIX:[^\s]+]]
337 ; CHECK-NEXT: landingpad { i8*, i32 }
338 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
339 ; CHECK-NEXT: br label %[[FIX]]
341 ; CHECK-NEXT: [[T1:%.*]] = phi i32 [ 0, %[[JOIN]] ], [ 1, %lpad ]
342 ; CHECK-NEXT: call void @use(i32 [[T1]])
343 ; CHECK-NEXT: call void @_ZSt9terminatev()
345 ; CHECK: attributes [[NUW]] = { nounwind }
346 ; CHECK: attributes #1 = { nounwind readnone }
347 ; CHECK: attributes #2 = { ssp uwtable }
348 ; CHECK: attributes #3 = { argmemonly nounwind }
349 ; CHECK: attributes #4 = { noreturn nounwind }