1 ; RUN: llc < %s -mtriple=s390x-linux-gnu -disable-block-placement | FileCheck %s
2 ; RUN: llc < %s -O0 -mtriple=s390x-linux-gnu -disable-block-placement | FileCheck --check-prefix=CHECK-O0 %s
4 declare i8* @malloc(i64)
5 declare void @free(i8*)
6 %swift_error = type {i64, i8}
8 ; This tests the basic usage of a swifterror parameter. "foo" is the function
9 ; that takes a swifterror parameter and "caller" is the caller of "foo".
10 define float @foo(%swift_error** swifterror %error_ptr_ref) {
13 ; CHECK: brasl %r14, malloc
14 ; CHECK: mvi 8(%r2), 1
16 ; CHECK-O0-LABEL: foo:
17 ; CHECK-O0: lghi %r2, 16
18 ; CHECK-O0: brasl %r14, malloc
19 ; CHECK-O0: lgr [[T0:%r[0-9]+]], %r2
20 ; CHECK-O0: mvi 8(%r2), 1
22 %call = call i8* @malloc(i64 16)
23 %call.0 = bitcast i8* %call to %swift_error*
24 store %swift_error* %call.0, %swift_error** %error_ptr_ref
25 %tmp = getelementptr inbounds i8, i8* %call, i64 8
30 ; "caller" calls "foo" that takes a swifterror parameter.
31 define float @caller(i8* %error_ref) {
32 ; CHECK-LABEL: caller:
33 ; Make a copy of error_ref because r2 is getting clobbered
34 ; CHECK: lgr %r[[REG1:[0-9]+]], %r2
36 ; CHECK: brasl %r14, foo
39 ; Access part of the error object and save it to error_ref
40 ; CHECK: lb %r[[REG2:[0-9]+]], 8(%r2)
41 ; CHECK: stc %r[[REG2]], 0(%r[[REG1]])
42 ; CHECK: brasl %r14, free
43 ; CHECK-O0-LABEL: caller:
44 ; CHECK-O0: lghi %r9, 0
45 ; CHECK-O0: brasl %r14, foo
46 ; CHECK-O0: cghi %r9, 0
49 %error_ptr_ref = alloca swifterror %swift_error*
50 store %swift_error* null, %swift_error** %error_ptr_ref
51 %call = call float @foo(%swift_error** swifterror %error_ptr_ref)
52 %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref
53 %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null
54 %tmp = bitcast %swift_error* %error_from_foo to i8*
55 br i1 %had_error_from_foo, label %handler, label %cont
57 %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1
59 store i8 %t, i8* %error_ref
62 call void @free(i8* %tmp)
66 ; "caller2" is the caller of "foo", it calls "foo" inside a loop.
67 define float @caller2(i8* %error_ref) {
68 ; CHECK-LABEL: caller2:
69 ; Make a copy of error_ref because r2 is getting clobbered
70 ; CHECK: lgr %r[[REG1:[0-9]+]], %r2
72 ; CHECK: brasl %r14, foo
73 ; CHECK: cgijlh %r9, 0,
76 ; Access part of the error object and save it to error_ref
77 ; CHECK: lb %r[[REG2:[0-9]+]], 8(%r9)
78 ; CHECK: stc %r[[REG2]], 0(%r[[REG1]])
80 ; CHECK: brasl %r14, free
81 ; CHECK-O0-LABEL: caller2:
82 ; CHECK-O0: lghi %r9, 0
83 ; CHECK-O0: brasl %r14, foo
84 ; CHECK-O0: cghi %r9, 0
87 %error_ptr_ref = alloca swifterror %swift_error*
90 store %swift_error* null, %swift_error** %error_ptr_ref
91 %call = call float @foo(%swift_error** swifterror %error_ptr_ref)
92 %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref
93 %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null
94 %tmp = bitcast %swift_error* %error_from_foo to i8*
95 br i1 %had_error_from_foo, label %handler, label %cont
97 %cmp = fcmp ogt float %call, 1.000000e+00
98 br i1 %cmp, label %bb_end, label %bb_loop
100 %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1
101 %t = load i8, i8* %v1
102 store i8 %t, i8* %error_ref
105 call void @free(i8* %tmp)
109 ; "foo_if" is a function that takes a swifterror parameter, it sets swifterror
110 ; under a certain condition.
111 define float @foo_if(%swift_error** swifterror %error_ptr_ref, i32 %cc) {
112 ; CHECK-LABEL: foo_if:
114 ; CHECK: lghi %r2, 16
115 ; CHECK: brasl %r14, malloc
116 ; CHECK: mvi 8(%r2), 1
117 ; CHECK: lgr %r9, %r2
120 ; CHECK-O0-LABEL: foo_if:
122 ; CHECK-O0: stg %r9, [[OFFS:[0-9]+]](%r15)
123 ; CHECK-O0: chi %r2, 0
125 ; CHECK-O0: lghi %r2, 16
126 ; CHECK-O0: brasl %r14, malloc
127 ; CHECK-O0: lgr %r9, %r2
128 ; CHECK-O0: mvi 8(%r2), 1
131 ; CHECK-O0: lg %r9, [[OFFS]](%r15)
134 %cond = icmp ne i32 %cc, 0
135 br i1 %cond, label %gen_error, label %normal
138 %call = call i8* @malloc(i64 16)
139 %call.0 = bitcast i8* %call to %swift_error*
140 store %swift_error* %call.0, %swift_error** %error_ptr_ref
141 %tmp = getelementptr inbounds i8, i8* %call, i64 8
149 ; "foo_loop" is a function that takes a swifterror parameter, it sets swifterror
150 ; under a certain condition inside a loop.
151 define float @foo_loop(%swift_error** swifterror %error_ptr_ref, i32 %cc, float %cc2) {
152 ; CHECK-LABEL: foo_loop:
153 ; CHECK: lr %r[[REG1:[0-9]+]], %r2
154 ; CHECK: cije %r[[REG1]], 0
155 ; CHECK: lghi %r2, 16
156 ; CHECK: brasl %r14, malloc
157 ; CHECK: mvi 8(%r2), 1
160 ; CHECK: lgr %r9, %r2
162 ; CHECK-O0-LABEL: foo_loop:
164 ; CHECK-O0: stg %r9, [[OFFS:[0-9]+]](%r15)
165 ; CHECK-O0: chi %r{{.*}}, 0
167 ; CHECK-O0: lghi %r2, 16
168 ; CHECK-O0: brasl %r14, malloc
169 ; CHECK-O0: lgr %r[[REG1:[0-9]+]], %r2
170 ; CHECK-O0: mvi 8(%r[[REG1]]), 1
173 ; CHECK-O0: lg %r9, [[OFFS:[0-9]+]](%r15)
179 %cond = icmp ne i32 %cc, 0
180 br i1 %cond, label %gen_error, label %bb_cont
183 %call = call i8* @malloc(i64 16)
184 %call.0 = bitcast i8* %call to %swift_error*
185 store %swift_error* %call.0, %swift_error** %error_ptr_ref
186 %tmp = getelementptr inbounds i8, i8* %call, i64 8
191 %cmp = fcmp ogt float %cc2, 1.000000e+00
192 br i1 %cmp, label %bb_end, label %bb_loop
197 %struct.S = type { i32, i32, i32, i32, i32, i32 }
199 ; "foo_sret" is a function that takes a swifterror parameter, it also has a sret
201 define void @foo_sret(%struct.S* sret(%struct.S) %agg.result, i32 %val1, %swift_error** swifterror %error_ptr_ref) {
202 ; CHECK-LABEL: foo_sret:
203 ; CHECK-DAG: lgr %r[[REG1:[0-9]+]], %r2
204 ; CHECK-DAG: lr %r[[REG2:[0-9]+]], %r3
205 ; CHECK: lghi %r2, 16
206 ; CHECK: brasl %r14, malloc
207 ; CHECK: mvi 8(%r2), 1
208 ; CHECK: st %r[[REG2]], 4(%r[[REG1]])
209 ; CHECK: lgr %r9, %r2
213 ; CHECK-O0-LABEL: foo_sret:
214 ; spill sret to stack
215 ; CHECK-O0-DAG: stg %r2, [[OFFS1:[0-9]+]](%r15)
216 ; CHECK-O0-DAG: st %r3, [[OFFS2:[0-9]+]](%r15)
217 ; CHECK-O0: lghi %r2, 16
218 ; CHECK-O0: brasl %r14, malloc
219 ; CHECK-O0-DAG: lgr %r[[REG3:[0-9]+]], %r2
220 ; CHECK-O0-DAG: mvi 8(%r[[REG3]]), 1
221 ; CHECK-O0-DAG: lg %r[[REG1:[0-9]+]], [[OFFS1]](%r15)
222 ; CHECK-O0-DAG: lgr %r9, %r[[REG3]]
223 ; CHECK-O0-DAG: l %r[[REG2:[0-9]+]], [[OFFS2]](%r15)
224 ; CHECK-O0: st %r[[REG2]], 4(%r[[REG1]])
227 %call = call i8* @malloc(i64 16)
228 %call.0 = bitcast i8* %call to %swift_error*
229 store %swift_error* %call.0, %swift_error** %error_ptr_ref
230 %tmp = getelementptr inbounds i8, i8* %call, i64 8
232 %v2 = getelementptr inbounds %struct.S, %struct.S* %agg.result, i32 0, i32 1
233 store i32 %val1, i32* %v2
237 ; "caller3" calls "foo_sret" that takes a swifterror parameter.
238 define float @caller3(i8* %error_ref) {
239 ; CHECK-LABEL: caller3:
240 ; Make a copy of error_ref because r2 is getting clobbered
241 ; CHECK: lgr %r[[REG1:[0-9]+]], %r2
244 ; CHECK: brasl %r14, foo_sret
246 ; Access part of the error object and save it to error_ref
247 ; CHECK: lb %r0, 8(%r2)
248 ; CHECK: stc %r0, 0(%r[[REG1]])
249 ; CHECK: brasl %r14, free
251 ; CHECK-O0-LABEL: caller3:
252 ; CHECK-O0: lghi %r9, 0
253 ; CHECK-O0: lhi %r3, 1
254 ; CHECK-O0: brasl %r14, foo_sret
255 ; CHECK-O0: lgr {{.*}}, %r9
256 ; CHECK-O0: cghi %r9, 0
258 ; Access part of the error object and save it to error_ref
259 ; CHECK-O0: lb %r0, 8(%r{{.*}})
260 ; CHECK-O0: stc %r0, 0(%r{{.*}})
262 ; CHECK-O0: lg %r2, {{.*}}(%r15)
263 ; CHECK-O0: brasl %r14, free
265 %s = alloca %struct.S, align 8
266 %error_ptr_ref = alloca swifterror %swift_error*
267 store %swift_error* null, %swift_error** %error_ptr_ref
268 call void @foo_sret(%struct.S* sret(%struct.S) %s, i32 1, %swift_error** swifterror %error_ptr_ref)
269 %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref
270 %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null
271 %tmp = bitcast %swift_error* %error_from_foo to i8*
272 br i1 %had_error_from_foo, label %handler, label %cont
274 %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1
275 %t = load i8, i8* %v1
276 store i8 %t, i8* %error_ref
279 call void @free(i8* %tmp)
283 ; This is a caller with multiple swifterror values, it calls "foo" twice, each
284 ; time with a different swifterror value, from "alloca swifterror".
285 define float @caller_with_multiple_swifterror_values(i8* %error_ref, i8* %error_ref2) {
286 ; CHECK-LABEL: caller_with_multiple_swifterror_values:
287 ; CHECK-DAG: lgr %r[[REG1:[0-9]+]], %r2
288 ; CHECK-DAG: lgr %r[[REG2:[0-9]+]], %r3
289 ; The first swifterror value:
291 ; CHECK: brasl %r14, foo
292 ; CHECK: ltgr %r2, %r9
294 ; Access part of the error object and save it to error_ref
295 ; CHECK: lb %r0, 8(%r2)
296 ; CHECK: stc %r0, 0(%r[[REG1]])
297 ; CHECK: brasl %r14, free
299 ; The second swifterror value:
301 ; CHECK: brasl %r14, foo
302 ; CHECK: ltgr %r2, %r9
304 ; Access part of the error object and save it to error_ref
305 ; CHECK: lb %r0, 8(%r2)
306 ; CHECK: stc %r0, 0(%r[[REG2]])
307 ; CHECK: brasl %r14, free
309 ; CHECK-O0-LABEL: caller_with_multiple_swifterror_values:
311 ; The first swifterror value:
312 ; CHECK-O0: lghi %r9, 0
313 ; CHECK-O0: brasl %r14, foo
316 ; The second swifterror value:
317 ; CHECK-O0: lghi %r9, 0
318 ; CHECK-O0: brasl %r14, foo
321 %error_ptr_ref = alloca swifterror %swift_error*
322 store %swift_error* null, %swift_error** %error_ptr_ref
323 %call = call float @foo(%swift_error** swifterror %error_ptr_ref)
324 %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref
325 %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null
326 %tmp = bitcast %swift_error* %error_from_foo to i8*
327 br i1 %had_error_from_foo, label %handler, label %cont
329 %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1
330 %t = load i8, i8* %v1
331 store i8 %t, i8* %error_ref
334 call void @free(i8* %tmp)
336 %error_ptr_ref2 = alloca swifterror %swift_error*
337 store %swift_error* null, %swift_error** %error_ptr_ref2
338 %call2 = call float @foo(%swift_error** swifterror %error_ptr_ref2)
339 %error_from_foo2 = load %swift_error*, %swift_error** %error_ptr_ref2
340 %had_error_from_foo2 = icmp ne %swift_error* %error_from_foo2, null
341 %bitcast2 = bitcast %swift_error* %error_from_foo2 to i8*
342 br i1 %had_error_from_foo2, label %handler2, label %cont2
344 %v2 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo2, i64 0, i32 1
345 %t2 = load i8, i8* %v2
346 store i8 %t2, i8* %error_ref2
349 call void @free(i8* %bitcast2)