1 ; RUN: opt < %s -inline -S | FileCheck %s
2 ; RUN: opt < %s -passes='cgscc(inline)' -S | FileCheck %s
3 ; RUN: opt < %s -passes='cgscc(inline)' -inline-enable-priority-order=true -S | FileCheck %s
5 ; Test that the inliner correctly handles inlining into invoke sites
6 ; by appending selectors and forwarding _Unwind_Resume directly to the
7 ; enclosing landing pad.
9 ;; Test 0 - basic functionality.
11 %struct.A = type { i8 }
13 @_ZTIi = external constant i8*
15 declare void @_ZN1AC1Ev(%struct.A*)
17 declare void @_ZN1AD1Ev(%struct.A*)
19 declare void @use(i32) nounwind
21 declare void @opaque()
23 declare i32 @llvm.eh.typeid.for(i8*) nounwind
25 declare i32 @__gxx_personality_v0(...)
27 declare i8* @__cxa_begin_catch(i8*)
29 declare void @__cxa_end_catch()
31 declare void @_ZSt9terminatev()
33 define internal void @test0_in() alwaysinline uwtable ssp personality i32 (...)* @__gxx_personality_v0 {
35 %a = alloca %struct.A, align 1
36 %b = alloca %struct.A, align 1
37 call void @_ZN1AC1Ev(%struct.A* %a)
38 invoke void @_ZN1AC1Ev(%struct.A* %b)
39 to label %invoke.cont unwind label %lpad
42 invoke void @_ZN1AD1Ev(%struct.A* %b)
43 to label %invoke.cont1 unwind label %lpad
46 call void @_ZN1AD1Ev(%struct.A* %a)
50 %exn = landingpad {i8*, i32}
52 invoke void @_ZN1AD1Ev(%struct.A* %a)
53 to label %invoke.cont2 unwind label %terminate.lpad
56 resume { i8*, i32 } %exn
59 %exn1 = landingpad {i8*, i32}
61 call void @_ZSt9terminatev() noreturn nounwind
65 define void @test0_out() uwtable ssp personality i32 (...)* @__gxx_personality_v0 {
67 invoke void @test0_in()
68 to label %ret unwind label %lpad
73 lpad: ; preds = %entry
74 %exn = landingpad {i8*, i32}
75 catch i8* bitcast (i8** @_ZTIi to i8*)
76 %eh.exc = extractvalue { i8*, i32 } %exn, 0
77 %eh.selector = extractvalue { i8*, i32 } %exn, 1
78 %0 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind
79 %1 = icmp eq i32 %eh.selector, %0
80 br i1 %1, label %catch, label %eh.resume
83 %ignored = call i8* @__cxa_begin_catch(i8* %eh.exc) nounwind
84 call void @__cxa_end_catch() nounwind
88 resume { i8*, i32 } %exn
91 ; CHECK: define void @test0_out()
92 ; CHECK: [[A:%.*]] = alloca %struct.A,
93 ; CHECK: [[B:%.*]] = alloca %struct.A,
94 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A]])
95 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B]])
96 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B]])
97 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
98 ; CHECK: landingpad { i8*, i32 }
100 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
101 ; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
102 ; CHECK-NEXT: to label %[[LBL:[^\s]+]] unwind
104 ; CHECK-NEXT: br label %[[LPAD:[^\s]+]]
106 ; CHECK: landingpad { i8*, i32 }
107 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
108 ; CHECK-NEXT: br label %[[LPAD]]
110 ; CHECK-NEXT: phi { i8*, i32 } [
111 ; CHECK-NEXT: extractvalue { i8*, i32 }
112 ; CHECK-NEXT: extractvalue { i8*, i32 }
113 ; CHECK-NEXT: call i32 @llvm.eh.typeid.for(
116 ;; Test 1 - Correctly handle phis in outer landing pads.
118 define void @test1_out() uwtable ssp personality i32 (...)* @__gxx_personality_v0 {
120 invoke void @test0_in()
121 to label %cont unwind label %lpad
124 invoke void @test0_in()
125 to label %ret unwind label %lpad
131 %x = phi i32 [ 0, %entry ], [ 1, %cont ]
132 %y = phi i32 [ 1, %entry ], [ 4, %cont ]
133 %exn = landingpad {i8*, i32}
134 catch i8* bitcast (i8** @_ZTIi to i8*)
135 %eh.exc = extractvalue { i8*, i32 } %exn, 0
136 %eh.selector = extractvalue { i8*, i32 } %exn, 1
137 %0 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind
138 %1 = icmp eq i32 %eh.selector, %0
139 br i1 %1, label %catch, label %eh.resume
142 %ignored = call i8* @__cxa_begin_catch(i8* %eh.exc) nounwind
143 call void @use(i32 %x)
144 call void @use(i32 %y)
145 call void @__cxa_end_catch() nounwind
149 resume { i8*, i32 } %exn
152 ; CHECK: define void @test1_out()
153 ; CHECK: [[A2:%.*]] = alloca %struct.A,
154 ; CHECK: [[B2:%.*]] = alloca %struct.A,
155 ; CHECK: [[A1:%.*]] = alloca %struct.A,
156 ; CHECK: [[B1:%.*]] = alloca %struct.A,
157 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A1]])
158 ; CHECK-NEXT: unwind label %[[LPAD:[^\s]+]]
159 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B1]])
160 ; CHECK-NEXT: unwind label %[[LPAD1:[^\s]+]]
161 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B1]])
162 ; CHECK-NEXT: unwind label %[[LPAD1]]
163 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A1]])
164 ; CHECK-NEXT: unwind label %[[LPAD]]
166 ; Inner landing pad from first inlining.
168 ; CHECK-NEXT: [[LPADVAL1:%.*]] = landingpad { i8*, i32 }
169 ; CHECK-NEXT: cleanup
170 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
171 ; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A1]])
172 ; CHECK-NEXT: to label %[[RESUME1:[^\s]+]] unwind
173 ; CHECK: [[RESUME1]]:
174 ; CHECK-NEXT: br label %[[LPAD_JOIN1:[^\s]+]]
176 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A2]])
177 ; CHECK-NEXT: unwind label %[[LPAD]]
178 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B2]])
179 ; CHECK-NEXT: unwind label %[[LPAD2:[^\s]+]]
180 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B2]])
181 ; CHECK-NEXT: unwind label %[[LPAD2]]
182 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A2]])
183 ; CHECK-NEXT: unwind label %[[LPAD]]
185 ; Inner landing pad from second inlining.
187 ; CHECK-NEXT: [[LPADVAL2:%.*]] = landingpad { i8*, i32 }
188 ; CHECK-NEXT: cleanup
189 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
190 ; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A2]])
191 ; CHECK-NEXT: to label %[[RESUME2:[^\s]+]] unwind
192 ; CHECK: [[RESUME2]]:
193 ; CHECK-NEXT: br label %[[LPAD_JOIN2:[^\s]+]]
198 ; CHECK-NEXT: [[X:%.*]] = phi i32 [ 0, %entry ], [ 0, {{%.*}} ], [ 1, %cont ], [ 1, {{%.*}} ]
199 ; CHECK-NEXT: [[Y:%.*]] = phi i32 [ 1, %entry ], [ 1, {{%.*}} ], [ 4, %cont ], [ 4, {{%.*}} ]
200 ; CHECK-NEXT: [[LPADVAL:%.*]] = landingpad { i8*, i32 }
201 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
202 ; CHECK-NEXT: br label %[[LPAD_JOIN2]]
204 ; CHECK: [[LPAD_JOIN2]]:
205 ; CHECK-NEXT: [[XJ2:%.*]] = phi i32 [ [[X]], %[[LPAD]] ], [ 1, %[[RESUME2]] ]
206 ; CHECK-NEXT: [[YJ2:%.*]] = phi i32 [ [[Y]], %[[LPAD]] ], [ 4, %[[RESUME2]] ]
207 ; CHECK-NEXT: [[EXNJ2:%.*]] = phi { i8*, i32 } [ [[LPADVAL]], %[[LPAD]] ], [ [[LPADVAL2]], %[[RESUME2]] ]
208 ; CHECK-NEXT: br label %[[LPAD_JOIN1]]
210 ; CHECK: [[LPAD_JOIN1]]:
211 ; CHECK-NEXT: [[XJ1:%.*]] = phi i32 [ [[XJ2]], %[[LPAD_JOIN2]] ], [ 0, %[[RESUME1]] ]
212 ; CHECK-NEXT: [[YJ1:%.*]] = phi i32 [ [[YJ2]], %[[LPAD_JOIN2]] ], [ 1, %[[RESUME1]] ]
213 ; CHECK-NEXT: [[EXNJ1:%.*]] = phi { i8*, i32 } [ [[EXNJ2]], %[[LPAD_JOIN2]] ], [ [[LPADVAL1]], %[[RESUME1]] ]
214 ; CHECK-NEXT: extractvalue { i8*, i32 } [[EXNJ1]], 0
215 ; CHECK-NEXT: [[SELJ1:%.*]] = extractvalue { i8*, i32 } [[EXNJ1]], 1
216 ; CHECK-NEXT: [[T:%.*]] = call i32 @llvm.eh.typeid.for(
217 ; CHECK-NEXT: icmp eq i32 [[SELJ1]], [[T]]
219 ; CHECK: call void @use(i32 [[XJ1]])
220 ; CHECK: call void @use(i32 [[YJ1]])
222 ; CHECK: resume { i8*, i32 }
225 ;; Test 2 - Don't make invalid IR for inlines into landing pads without eh.exception calls
226 define void @test2_out() uwtable ssp personality i32 (...)* @__gxx_personality_v0 {
228 invoke void @test0_in()
229 to label %ret unwind label %lpad
235 %exn = landingpad {i8*, i32}
237 call void @_ZSt9terminatev()
241 ; CHECK: define void @test2_out()
242 ; CHECK: [[A:%.*]] = alloca %struct.A,
243 ; CHECK: [[B:%.*]] = alloca %struct.A,
244 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A]])
245 ; CHECK-NEXT: unwind label %[[LPAD:[^\s]+]]
246 ; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B]])
247 ; CHECK-NEXT: unwind label %[[LPAD2:[^\s]+]]
248 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B]])
249 ; CHECK-NEXT: unwind label %[[LPAD2]]
250 ; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
251 ; CHECK-NEXT: unwind label %[[LPAD]]
254 ;; Test 3 - Deal correctly with split unwind edges.
255 define void @test3_out() uwtable ssp personality i32 (...)* @__gxx_personality_v0 {
257 invoke void @test0_in()
258 to label %ret unwind label %lpad
264 %exn = landingpad {i8*, i32}
265 catch i8* bitcast (i8** @_ZTIi to i8*)
269 call void @_ZSt9terminatev()
273 ; CHECK: define void @test3_out()
274 ; CHECK: landingpad { i8*, i32 }
275 ; CHECK-NEXT: cleanup
276 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
277 ; CHECK-NEXT: invoke void @_ZN1AD1Ev(
278 ; CHECK-NEXT: to label %[[L:[^\s]+]] unwind
280 ; CHECK-NEXT: br label %[[JOIN:[^\s]+]]
282 ; CHECK-NEXT: phi { i8*, i32 }
283 ; CHECK-NEXT: br label %lpad.cont
285 ; CHECK-NEXT: call void @_ZSt9terminatev()
288 ;; Test 4 - Split unwind edges with a dominance problem
289 define void @test4_out() uwtable ssp personality i32 (...)* @__gxx_personality_v0 {
291 invoke void @test0_in()
292 to label %cont unwind label %lpad.crit
295 invoke void @opaque()
296 to label %ret unwind label %lpad
302 %exn = landingpad {i8*, i32}
303 catch i8* bitcast (i8** @_ZTIi to i8*)
304 call void @opaque() nounwind
308 %exn2 = landingpad {i8*, i32}
309 catch i8* bitcast (i8** @_ZTIi to i8*)
313 %phi = phi i32 [ 0, %lpad.crit ], [ 1, %lpad ]
314 call void @use(i32 %phi)
315 call void @_ZSt9terminatev()
319 ; CHECK: define void @test4_out()
320 ; CHECK: landingpad { i8*, i32 }
321 ; CHECK-NEXT: cleanup
322 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
323 ; CHECK-NEXT: invoke void @_ZN1AD1Ev(
324 ; CHECK-NEXT: to label %[[L:[^\s]+]] unwind
326 ; CHECK-NEXT: br label %[[JOIN:[^\s]+]]
327 ; CHECK: invoke void @opaque()
328 ; CHECK-NEXT: unwind label %lpad
330 ; CHECK-NEXT: landingpad { i8*, i32 }
331 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
332 ; CHECK-NEXT: br label %[[JOIN]]
334 ; CHECK-NEXT: phi { i8*, i32 }
335 ; CHECK-NEXT: call void @opaque() [[NUW:#[0-9]+]]
336 ; CHECK-NEXT: br label %[[FIX:[^\s]+]]
338 ; CHECK-NEXT: landingpad { i8*, i32 }
339 ; CHECK-NEXT: catch i8* bitcast (i8** @_ZTIi to i8*)
340 ; CHECK-NEXT: br label %[[FIX]]
342 ; CHECK-NEXT: [[T1:%.*]] = phi i32 [ 0, %[[JOIN]] ], [ 1, %lpad ]
343 ; CHECK-NEXT: call void @use(i32 [[T1]])
344 ; CHECK-NEXT: call void @_ZSt9terminatev()
346 ; CHECK: attributes [[NUW]] = { nounwind }
347 ; CHECK: attributes #1 = { nounwind readnone }
348 ; CHECK: attributes #2 = { ssp uwtable }
349 ; CHECK: attributes #3 = { argmemonly nofree nosync nounwind willreturn }
350 ; CHECK: attributes #4 = { noreturn nounwind }