blob: 5f657387c21e2d141bc1167dbb936a31a1e244d6 [file] [log] [blame]
John McCallbd04b742011-05-27 18:34:38 +00001; RUN: opt < %s -inline -S | FileCheck %s
2
3; Test that the inliner correctly handles inlining into invoke sites
4; by appending selectors and forwarding _Unwind_Resume directly to the
5; enclosing landing pad.
6
John McCallfca77862011-06-01 02:17:11 +00007;; Test 0 - basic functionality.
John McCallf19cf992011-05-30 01:08:04 +00008
John McCallbd04b742011-05-27 18:34:38 +00009%struct.A = type { i8 }
10
11@_ZTIi = external constant i8*
12
13declare void @_ZN1AC1Ev(%struct.A*)
14
15declare void @_ZN1AD1Ev(%struct.A*)
16
John McCallf19cf992011-05-30 01:08:04 +000017declare void @use(i32) nounwind
18
John McCallbd04b742011-05-27 18:34:38 +000019declare i8* @llvm.eh.exception() nounwind readonly
20
21declare i32 @llvm.eh.selector(i8*, i8*, ...) nounwind
22
23declare i32 @llvm.eh.typeid.for(i8*) nounwind
24
John McCall046c47e2011-05-28 07:45:59 +000025declare void @llvm.eh.resume(i8*, i32)
John McCallbd04b742011-05-27 18:34:38 +000026
27declare i32 @__gxx_personality_v0(...)
28
29declare i8* @__cxa_begin_catch(i8*)
30
31declare void @__cxa_end_catch()
32
33declare void @_ZSt9terminatev()
34
35define internal void @test0_in() alwaysinline uwtable ssp {
36entry:
37 %a = alloca %struct.A, align 1
38 %b = alloca %struct.A, align 1
39 call void @_ZN1AC1Ev(%struct.A* %a)
40 invoke void @_ZN1AC1Ev(%struct.A* %b)
41 to label %invoke.cont unwind label %lpad
42
43invoke.cont:
44 invoke void @_ZN1AD1Ev(%struct.A* %b)
45 to label %invoke.cont1 unwind label %lpad
46
47invoke.cont1:
48 call void @_ZN1AD1Ev(%struct.A* %a)
49 ret void
50
51lpad:
52 %exn = call i8* @llvm.eh.exception() nounwind
53 %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 0) nounwind
54 invoke void @_ZN1AD1Ev(%struct.A* %a)
55 to label %invoke.cont2 unwind label %terminate.lpad
56
57invoke.cont2:
John McCall046c47e2011-05-28 07:45:59 +000058 call void @llvm.eh.resume(i8* %exn, i32 %eh.selector) noreturn
John McCallbd04b742011-05-27 18:34:38 +000059 unreachable
60
61terminate.lpad:
62 %exn3 = call i8* @llvm.eh.exception() nounwind
63 %eh.selector4 = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn3, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* null) nounwind
64 call void @_ZSt9terminatev() noreturn nounwind
65 unreachable
66}
67
68define void @test0_out() uwtable ssp {
69entry:
70 invoke void @test0_in()
71 to label %ret unwind label %lpad
72
73ret:
74 ret void
75
76lpad: ; preds = %entry
77 %exn = call i8* @llvm.eh.exception() nounwind
78 %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* bitcast (i8** @_ZTIi to i8*)) nounwind
79 %0 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind
80 %1 = icmp eq i32 %eh.selector, %0
81 br i1 %1, label %catch, label %eh.resume
82
83catch:
84 %ignored = call i8* @__cxa_begin_catch(i8* %exn) nounwind
85 call void @__cxa_end_catch() nounwind
86 br label %ret
87
88eh.resume:
John McCall046c47e2011-05-28 07:45:59 +000089 call void @llvm.eh.resume(i8* %exn, i32 %eh.selector) noreturn
John McCallbd04b742011-05-27 18:34:38 +000090 unreachable
91}
92
John McCall046c47e2011-05-28 07:45:59 +000093; CHECK: define void @test0_out()
94; CHECK: [[A:%.*]] = alloca %struct.A,
95; CHECK: [[B:%.*]] = alloca %struct.A,
96; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A]])
97; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B]])
98; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B]])
99; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
100; CHECK: call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* {{%.*}}, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 0, i8* bitcast (i8** @_ZTIi to i8*))
John McCallbd04b742011-05-27 18:34:38 +0000101; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
102; CHECK-NEXT: to label %[[LBL:[^\s]+]] unwind
103; CHECK: [[LBL]]:
104; CHECK-NEXT: br label %[[LPAD:[^\s]+]]
John McCall046c47e2011-05-28 07:45:59 +0000105; CHECK: ret void
106; CHECK: call i8* @llvm.eh.exception()
John McCallbd04b742011-05-27 18:34:38 +0000107; CHECK-NEXT: call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* {{%.*}}, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* bitcast (i8** @_ZTIi to i8*))
John McCall046c47e2011-05-28 07:45:59 +0000108; CHECK-NEXT: br label %[[LPAD]]
109; CHECK: [[LPAD]]:
110; CHECK-NEXT: phi i8* [
111; CHECK-NEXT: phi i32 [
John McCallf19cf992011-05-30 01:08:04 +0000112; CHECK-NEXT: call i32 @llvm.eh.typeid.for(
113
114
John McCallfca77862011-06-01 02:17:11 +0000115;; Test 1 - Correctly handle phis in outer landing pads.
John McCallf19cf992011-05-30 01:08:04 +0000116
117define void @test1_out() uwtable ssp {
118entry:
119 invoke void @test0_in()
120 to label %cont unwind label %lpad
121
122cont:
123 invoke void @test0_in()
124 to label %ret unwind label %lpad
125
126ret:
127 ret void
128
129lpad:
130 %x = phi i32 [ 0, %entry ], [ 1, %cont ]
131 %y = phi i32 [ 1, %entry ], [ 4, %cont ]
132 %exn = call i8* @llvm.eh.exception() nounwind
133 %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* bitcast (i8** @_ZTIi to i8*)) nounwind
134 %0 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind
135 %1 = icmp eq i32 %eh.selector, %0
136 br i1 %1, label %catch, label %eh.resume
137
138catch:
139 %ignored = call i8* @__cxa_begin_catch(i8* %exn) nounwind
140 call void @use(i32 %x)
141 call void @use(i32 %y)
142 call void @__cxa_end_catch() nounwind
143 br label %ret
144
145eh.resume:
146 call void @llvm.eh.resume(i8* %exn, i32 %eh.selector) noreturn
147 unreachable
148}
149
150; CHECK: define void @test1_out()
151; CHECK: [[A2:%.*]] = alloca %struct.A,
152; CHECK: [[B2:%.*]] = alloca %struct.A,
153; CHECK: [[A1:%.*]] = alloca %struct.A,
154; CHECK: [[B1:%.*]] = alloca %struct.A,
155; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A1]])
156; CHECK-NEXT: unwind label %[[LPAD:[^\s]+]]
157; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B1]])
158; CHECK-NEXT: unwind label %[[LPAD1:[^\s]+]]
159; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B1]])
160; CHECK-NEXT: unwind label %[[LPAD1]]
161; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A1]])
162; CHECK-NEXT: unwind label %[[LPAD]]
163
164; Inner landing pad from first inlining.
165; CHECK: [[LPAD1]]:
166; CHECK-NEXT: [[EXN1:%.*]] = call i8* @llvm.eh.exception()
167; CHECK-NEXT: [[SEL1:%.*]] = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* [[EXN1]], i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 0, i8* bitcast (i8** @_ZTIi to i8*))
168; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A1]])
169; CHECK-NEXT: to label %[[RESUME1:[^\s]+]] unwind
170; CHECK: [[RESUME1]]:
171; CHECK-NEXT: br label %[[LPAD_JOIN1:[^\s]+]]
172
173; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A2]])
174; CHECK-NEXT: unwind label %[[LPAD]]
175; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B2]])
176; CHECK-NEXT: unwind label %[[LPAD2:[^\s]+]]
177; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B2]])
178; CHECK-NEXT: unwind label %[[LPAD2]]
179; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A2]])
180; CHECK-NEXT: unwind label %[[LPAD]]
181
182; Inner landing pad from second inlining.
183; CHECK: [[LPAD2]]:
184; CHECK-NEXT: [[EXN2:%.*]] = call i8* @llvm.eh.exception()
185; CHECK-NEXT: [[SEL2:%.*]] = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* [[EXN2]], i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 0, i8* bitcast (i8** @_ZTIi to i8*))
186; CHECK-NEXT: invoke void @_ZN1AD1Ev(%struct.A* [[A2]])
187; CHECK-NEXT: to label %[[RESUME2:[^\s]+]] unwind
188; CHECK: [[RESUME2]]:
189; CHECK-NEXT: br label %[[LPAD_JOIN2:[^\s]+]]
190
191; CHECK: ret void
192
193; CHECK: [[LPAD]]:
194; CHECK-NEXT: [[X:%.*]] = phi i32 [ 0, %entry ], [ 0, {{%.*}} ], [ 1, %cont ], [ 1, {{%.*}} ]
195; CHECK-NEXT: [[Y:%.*]] = phi i32 [ 1, %entry ], [ 1, {{%.*}} ], [ 4, %cont ], [ 4, {{%.*}} ]
196; CHECK-NEXT: [[EXN:%.*]] = call i8* @llvm.eh.exception()
197; CHECK-NEXT: [[SEL:%.*]] = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* [[EXN]], i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* bitcast (i8** @_ZTIi to i8*))
198; CHECK-NEXT: br label %[[LPAD_JOIN2]]
199
200; CHECK: [[LPAD_JOIN2]]:
201; CHECK-NEXT: [[XJ2:%.*]] = phi i32 [ [[X]], %[[LPAD]] ], [ 1, %[[RESUME2]] ]
202; CHECK-NEXT: [[YJ2:%.*]] = phi i32 [ [[Y]], %[[LPAD]] ], [ 4, %[[RESUME2]] ]
203; CHECK-NEXT: [[EXNJ2:%.*]] = phi i8* [ [[EXN]], %[[LPAD]] ], [ [[EXN2]], %[[RESUME2]] ]
204; CHECK-NEXT: [[SELJ2:%.*]] = phi i32 [ [[SEL]], %[[LPAD]] ], [ [[SEL2]], %[[RESUME2]] ]
205; CHECK-NEXT: br label %[[LPAD_JOIN1]]
206
207; CHECK: [[LPAD_JOIN1]]:
208; CHECK-NEXT: [[XJ1:%.*]] = phi i32 [ [[XJ2]], %[[LPAD_JOIN2]] ], [ 0, %[[RESUME1]] ]
209; CHECK-NEXT: [[YJ1:%.*]] = phi i32 [ [[YJ2]], %[[LPAD_JOIN2]] ], [ 1, %[[RESUME1]] ]
210; CHECK-NEXT: [[EXNJ1:%.*]] = phi i8* [ [[EXNJ2]], %[[LPAD_JOIN2]] ], [ [[EXN1]], %[[RESUME1]] ]
211; CHECK-NEXT: [[SELJ1:%.*]] = phi i32 [ [[SELJ2]], %[[LPAD_JOIN2]] ], [ [[SEL1]], %[[RESUME1]] ]
212; CHECK-NEXT: [[T:%.*]] = call i32 @llvm.eh.typeid.for(
213; CHECK-NEXT: icmp eq i32 [[SELJ1]], [[T]]
214
215; CHECK: call void @use(i32 [[XJ1]])
216; CHECK: call void @use(i32 [[YJ1]])
217
218; CHECK: call void @llvm.eh.resume(i8* [[EXNJ1]], i32 [[SELJ1]])
John McCallfca77862011-06-01 02:17:11 +0000219
220;; Test 2 - Don't make invalid IR for inlines into landing pads without eh.exception calls
221
222define void @test2_out() uwtable ssp {
223entry:
224 invoke void @test0_in()
225 to label %ret unwind label %lpad
226
227ret:
228 ret void
229
230lpad:
231 call void @_ZSt9terminatev()
232 unreachable
233}
234
235; CHECK: define void @test2_out()
236; CHECK: [[A:%.*]] = alloca %struct.A,
237; CHECK: [[B:%.*]] = alloca %struct.A,
238; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[A]])
239; CHECK-NEXT: unwind label %[[LPAD:[^\s]+]]
240; CHECK: invoke void @_ZN1AC1Ev(%struct.A* [[B]])
241; CHECK-NEXT: unwind label %[[LPAD2:[^\s]+]]
242; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[B]])
243; CHECK-NEXT: unwind label %[[LPAD2]]
244; CHECK: invoke void @_ZN1AD1Ev(%struct.A* [[A]])
245; CHECK-NEXT: unwind label %[[LPAD]]