xref: /aosp_15_r20/external/llvm/test/CodeGen/SystemZ/swifterror.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=s390x-linux-gnu| FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -O0 -mtriple=s390x-linux-gnu | FileCheck --check-prefix=CHECK-O0 %s
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Workerdeclare i8* @malloc(i64)
5*9880d681SAndroid Build Coastguard Workerdeclare void @free(i8*)
6*9880d681SAndroid Build Coastguard Worker%swift_error = type {i64, i8}
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Worker; This tests the basic usage of a swifterror parameter. "foo" is the function
9*9880d681SAndroid Build Coastguard Worker; that takes a swifterror parameter and "caller" is the caller of "foo".
10*9880d681SAndroid Build Coastguard Workerdefine float @foo(%swift_error** swifterror %error_ptr_ref) {
11*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: foo:
12*9880d681SAndroid Build Coastguard Worker; CHECK: lghi %r2, 16
13*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, malloc
14*9880d681SAndroid Build Coastguard Worker; CHECK: mvi 8(%r2), 1
15*9880d681SAndroid Build Coastguard Worker; CHECK: lgr %r9, %r2
16*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: foo:
17*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lghi %r2, 16
18*9880d681SAndroid Build Coastguard Worker; CHECK-O0: brasl %r14, malloc
19*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lgr %r[[REG1:[0-9]+]], %r2
20*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mvi 8(%r2), 1
21*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lgr %r9, %r[[REG1]]
22*9880d681SAndroid Build Coastguard Workerentry:
23*9880d681SAndroid Build Coastguard Worker  %call = call i8* @malloc(i64 16)
24*9880d681SAndroid Build Coastguard Worker  %call.0 = bitcast i8* %call to %swift_error*
25*9880d681SAndroid Build Coastguard Worker  store %swift_error* %call.0, %swift_error** %error_ptr_ref
26*9880d681SAndroid Build Coastguard Worker  %tmp = getelementptr inbounds i8, i8* %call, i64 8
27*9880d681SAndroid Build Coastguard Worker  store i8 1, i8* %tmp
28*9880d681SAndroid Build Coastguard Worker  ret float 1.0
29*9880d681SAndroid Build Coastguard Worker}
30*9880d681SAndroid Build Coastguard Worker
31*9880d681SAndroid Build Coastguard Worker; "caller" calls "foo" that takes a swifterror parameter.
32*9880d681SAndroid Build Coastguard Workerdefine float @caller(i8* %error_ref) {
33*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: caller:
34*9880d681SAndroid Build Coastguard Worker; Make a copy of error_ref because r2 is getting clobbered
35*9880d681SAndroid Build Coastguard Worker; CHECK: lgr %r[[REG1:[0-9]+]], %r2
36*9880d681SAndroid Build Coastguard Worker; CHECK: lghi %r9, 0
37*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, foo
38*9880d681SAndroid Build Coastguard Worker; CHECK: cgijlh %r9, 0,
39*9880d681SAndroid Build Coastguard Worker; Access part of the error object and save it to error_ref
40*9880d681SAndroid Build Coastguard Worker; CHECK: lb %r[[REG2:[0-9]+]], 8(%r9)
41*9880d681SAndroid Build Coastguard Worker; CHECK: stc %r[[REG2]], 0(%r[[REG1]])
42*9880d681SAndroid Build Coastguard Worker; CHECK: lgr %r2, %r9
43*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, free
44*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: caller:
45*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lghi %r9, 0
46*9880d681SAndroid Build Coastguard Worker; CHECK-O0: brasl %r14, foo
47*9880d681SAndroid Build Coastguard Worker; CHECK-O0: cghi %r9, 0
48*9880d681SAndroid Build Coastguard Worker; CHECK-O0: jlh
49*9880d681SAndroid Build Coastguard Workerentry:
50*9880d681SAndroid Build Coastguard Worker  %error_ptr_ref = alloca swifterror %swift_error*
51*9880d681SAndroid Build Coastguard Worker  store %swift_error* null, %swift_error** %error_ptr_ref
52*9880d681SAndroid Build Coastguard Worker  %call = call float @foo(%swift_error** swifterror %error_ptr_ref)
53*9880d681SAndroid Build Coastguard Worker  %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref
54*9880d681SAndroid Build Coastguard Worker  %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null
55*9880d681SAndroid Build Coastguard Worker  %tmp = bitcast %swift_error* %error_from_foo to i8*
56*9880d681SAndroid Build Coastguard Worker  br i1 %had_error_from_foo, label %handler, label %cont
57*9880d681SAndroid Build Coastguard Workercont:
58*9880d681SAndroid Build Coastguard Worker  %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1
59*9880d681SAndroid Build Coastguard Worker  %t = load i8, i8* %v1
60*9880d681SAndroid Build Coastguard Worker  store i8 %t, i8* %error_ref
61*9880d681SAndroid Build Coastguard Worker  br label %handler
62*9880d681SAndroid Build Coastguard Workerhandler:
63*9880d681SAndroid Build Coastguard Worker  call void @free(i8* %tmp)
64*9880d681SAndroid Build Coastguard Worker  ret float 1.0
65*9880d681SAndroid Build Coastguard Worker}
66*9880d681SAndroid Build Coastguard Worker
67*9880d681SAndroid Build Coastguard Worker; "caller2" is the caller of "foo", it calls "foo" inside a loop.
68*9880d681SAndroid Build Coastguard Workerdefine float @caller2(i8* %error_ref) {
69*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: caller2:
70*9880d681SAndroid Build Coastguard Worker; Make a copy of error_ref because r2 is getting clobbered
71*9880d681SAndroid Build Coastguard Worker; CHECK: lgr %r[[REG1:[0-9]+]], %r2
72*9880d681SAndroid Build Coastguard Worker; CHECK: lghi %r9, 0
73*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, foo
74*9880d681SAndroid Build Coastguard Worker; CHECK: cgijlh %r9, 0,
75*9880d681SAndroid Build Coastguard Worker; CHECK: ceb %f0,
76*9880d681SAndroid Build Coastguard Worker; CHECK: jnh
77*9880d681SAndroid Build Coastguard Worker; Access part of the error object and save it to error_ref
78*9880d681SAndroid Build Coastguard Worker; CHECK: lb %r[[REG2:[0-9]+]], 8(%r9)
79*9880d681SAndroid Build Coastguard Worker; CHECK: stc %r[[REG2]], 0(%r[[REG1]])
80*9880d681SAndroid Build Coastguard Worker; CHECK: lgr %r2, %r9
81*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, free
82*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: caller2:
83*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lghi %r9, 0
84*9880d681SAndroid Build Coastguard Worker; CHECK-O0: brasl %r14, foo
85*9880d681SAndroid Build Coastguard Worker; CHECK-O0: cghi %r9, 0
86*9880d681SAndroid Build Coastguard Worker; CHECK-O0: jlh
87*9880d681SAndroid Build Coastguard Workerentry:
88*9880d681SAndroid Build Coastguard Worker  %error_ptr_ref = alloca swifterror %swift_error*
89*9880d681SAndroid Build Coastguard Worker  br label %bb_loop
90*9880d681SAndroid Build Coastguard Workerbb_loop:
91*9880d681SAndroid Build Coastguard Worker  store %swift_error* null, %swift_error** %error_ptr_ref
92*9880d681SAndroid Build Coastguard Worker  %call = call float @foo(%swift_error** swifterror %error_ptr_ref)
93*9880d681SAndroid Build Coastguard Worker  %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref
94*9880d681SAndroid Build Coastguard Worker  %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null
95*9880d681SAndroid Build Coastguard Worker  %tmp = bitcast %swift_error* %error_from_foo to i8*
96*9880d681SAndroid Build Coastguard Worker  br i1 %had_error_from_foo, label %handler, label %cont
97*9880d681SAndroid Build Coastguard Workercont:
98*9880d681SAndroid Build Coastguard Worker  %cmp = fcmp ogt float %call, 1.000000e+00
99*9880d681SAndroid Build Coastguard Worker  br i1 %cmp, label %bb_end, label %bb_loop
100*9880d681SAndroid Build Coastguard Workerbb_end:
101*9880d681SAndroid Build Coastguard Worker  %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1
102*9880d681SAndroid Build Coastguard Worker  %t = load i8, i8* %v1
103*9880d681SAndroid Build Coastguard Worker  store i8 %t, i8* %error_ref
104*9880d681SAndroid Build Coastguard Worker  br label %handler
105*9880d681SAndroid Build Coastguard Workerhandler:
106*9880d681SAndroid Build Coastguard Worker  call void @free(i8* %tmp)
107*9880d681SAndroid Build Coastguard Worker  ret float 1.0
108*9880d681SAndroid Build Coastguard Worker}
109*9880d681SAndroid Build Coastguard Worker
110*9880d681SAndroid Build Coastguard Worker; "foo_if" is a function that takes a swifterror parameter, it sets swifterror
111*9880d681SAndroid Build Coastguard Worker; under a certain condition.
112*9880d681SAndroid Build Coastguard Workerdefine float @foo_if(%swift_error** swifterror %error_ptr_ref, i32 %cc) {
113*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: foo_if:
114*9880d681SAndroid Build Coastguard Worker; CHECK: cije %r2, 0
115*9880d681SAndroid Build Coastguard Worker; CHECK: lghi %r2, 16
116*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, malloc
117*9880d681SAndroid Build Coastguard Worker; CHECK: mvi 8(%r2), 1
118*9880d681SAndroid Build Coastguard Worker; CHECK: lgr %r9, %r2
119*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: %r9
120*9880d681SAndroid Build Coastguard Worker; CHECK: br %r14
121*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: foo_if:
122*9880d681SAndroid Build Coastguard Worker; CHECK-O0: chi %r2, 0
123*9880d681SAndroid Build Coastguard Worker; spill to stack
124*9880d681SAndroid Build Coastguard Worker; CHECK-O0: stg %r9, [[OFFS:[0-9]+]](%r15)
125*9880d681SAndroid Build Coastguard Worker; CHECK-O0: je
126*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lghi %r2, 16
127*9880d681SAndroid Build Coastguard Worker; CHECK-O0: brasl %r14, malloc
128*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lgr %r[[REG1:[0-9]+]], %r2
129*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mvi 8(%r2), 1
130*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lgr %r9, %r[[REG1]]
131*9880d681SAndroid Build Coastguard Worker; CHECK-O0: br %r14
132*9880d681SAndroid Build Coastguard Worker; reload from stack
133*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lg %r9, [[OFFS]](%r15)
134*9880d681SAndroid Build Coastguard Worker; CHECK-O0: br %r14
135*9880d681SAndroid Build Coastguard Workerentry:
136*9880d681SAndroid Build Coastguard Worker  %cond = icmp ne i32 %cc, 0
137*9880d681SAndroid Build Coastguard Worker  br i1 %cond, label %gen_error, label %normal
138*9880d681SAndroid Build Coastguard Worker
139*9880d681SAndroid Build Coastguard Workergen_error:
140*9880d681SAndroid Build Coastguard Worker  %call = call i8* @malloc(i64 16)
141*9880d681SAndroid Build Coastguard Worker  %call.0 = bitcast i8* %call to %swift_error*
142*9880d681SAndroid Build Coastguard Worker  store %swift_error* %call.0, %swift_error** %error_ptr_ref
143*9880d681SAndroid Build Coastguard Worker  %tmp = getelementptr inbounds i8, i8* %call, i64 8
144*9880d681SAndroid Build Coastguard Worker  store i8 1, i8* %tmp
145*9880d681SAndroid Build Coastguard Worker  ret float 1.0
146*9880d681SAndroid Build Coastguard Worker
147*9880d681SAndroid Build Coastguard Workernormal:
148*9880d681SAndroid Build Coastguard Worker  ret float 0.0
149*9880d681SAndroid Build Coastguard Worker}
150*9880d681SAndroid Build Coastguard Worker
151*9880d681SAndroid Build Coastguard Worker; "foo_loop" is a function that takes a swifterror parameter, it sets swifterror
152*9880d681SAndroid Build Coastguard Worker; under a certain condition inside a loop.
153*9880d681SAndroid Build Coastguard Workerdefine float @foo_loop(%swift_error** swifterror %error_ptr_ref, i32 %cc, float %cc2) {
154*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: foo_loop:
155*9880d681SAndroid Build Coastguard Worker; CHECK: lr %r[[REG1:[0-9]+]], %r2
156*9880d681SAndroid Build Coastguard Worker; CHECK: cije %r[[REG1]], 0
157*9880d681SAndroid Build Coastguard Worker; CHECK: lghi %r2, 16
158*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, malloc
159*9880d681SAndroid Build Coastguard Worker; CHECK: mvi 8(%r2), 1
160*9880d681SAndroid Build Coastguard Worker; CHECK: ceb %f8,
161*9880d681SAndroid Build Coastguard Worker; CHECK: jnh
162*9880d681SAndroid Build Coastguard Worker; CHECK: lgr %r9, %r2
163*9880d681SAndroid Build Coastguard Worker; CHECK: br %r14
164*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: foo_loop:
165*9880d681SAndroid Build Coastguard Worker; spill to stack
166*9880d681SAndroid Build Coastguard Worker; CHECK-O0: stg %r9, [[OFFS:[0-9]+]](%r15)
167*9880d681SAndroid Build Coastguard Worker; CHECK-O0: chi %r{{.*}}, 0
168*9880d681SAndroid Build Coastguard Worker; CHECK-O0: je
169*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lghi %r2, 16
170*9880d681SAndroid Build Coastguard Worker; CHECK-O0: brasl %r14, malloc
171*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lgr %r[[REG1:[0-9]+]], %r2
172*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mvi 8(%r2), 1
173*9880d681SAndroid Build Coastguard Worker; CHECK-O0: jnh
174*9880d681SAndroid Build Coastguard Worker; reload from stack
175*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lg %r9, [[OFFS:[0-9]+]](%r15)
176*9880d681SAndroid Build Coastguard Worker; CHECK-O0: br %r14
177*9880d681SAndroid Build Coastguard Workerentry:
178*9880d681SAndroid Build Coastguard Worker  br label %bb_loop
179*9880d681SAndroid Build Coastguard Worker
180*9880d681SAndroid Build Coastguard Workerbb_loop:
181*9880d681SAndroid Build Coastguard Worker  %cond = icmp ne i32 %cc, 0
182*9880d681SAndroid Build Coastguard Worker  br i1 %cond, label %gen_error, label %bb_cont
183*9880d681SAndroid Build Coastguard Worker
184*9880d681SAndroid Build Coastguard Workergen_error:
185*9880d681SAndroid Build Coastguard Worker  %call = call i8* @malloc(i64 16)
186*9880d681SAndroid Build Coastguard Worker  %call.0 = bitcast i8* %call to %swift_error*
187*9880d681SAndroid Build Coastguard Worker  store %swift_error* %call.0, %swift_error** %error_ptr_ref
188*9880d681SAndroid Build Coastguard Worker  %tmp = getelementptr inbounds i8, i8* %call, i64 8
189*9880d681SAndroid Build Coastguard Worker  store i8 1, i8* %tmp
190*9880d681SAndroid Build Coastguard Worker  br label %bb_cont
191*9880d681SAndroid Build Coastguard Worker
192*9880d681SAndroid Build Coastguard Workerbb_cont:
193*9880d681SAndroid Build Coastguard Worker  %cmp = fcmp ogt float %cc2, 1.000000e+00
194*9880d681SAndroid Build Coastguard Worker  br i1 %cmp, label %bb_end, label %bb_loop
195*9880d681SAndroid Build Coastguard Workerbb_end:
196*9880d681SAndroid Build Coastguard Worker  ret float 0.0
197*9880d681SAndroid Build Coastguard Worker}
198*9880d681SAndroid Build Coastguard Worker
199*9880d681SAndroid Build Coastguard Worker%struct.S = type { i32, i32, i32, i32, i32, i32 }
200*9880d681SAndroid Build Coastguard Worker
201*9880d681SAndroid Build Coastguard Worker; "foo_sret" is a function that takes a swifterror parameter, it also has a sret
202*9880d681SAndroid Build Coastguard Worker; parameter.
203*9880d681SAndroid Build Coastguard Workerdefine void @foo_sret(%struct.S* sret %agg.result, i32 %val1, %swift_error** swifterror %error_ptr_ref) {
204*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: foo_sret:
205*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: lgr %r[[REG1:[0-9]+]], %r2
206*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: lr %r[[REG2:[0-9]+]], %r3
207*9880d681SAndroid Build Coastguard Worker; CHECK: lghi %r2, 16
208*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, malloc
209*9880d681SAndroid Build Coastguard Worker; CHECK: mvi 8(%r2), 1
210*9880d681SAndroid Build Coastguard Worker; CHECK: st %r[[REG2]], 4(%r[[REG1]])
211*9880d681SAndroid Build Coastguard Worker; CHECK: lgr %r9, %r2
212*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: %r9
213*9880d681SAndroid Build Coastguard Worker; CHECK: br %r14
214*9880d681SAndroid Build Coastguard Worker
215*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: foo_sret:
216*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lghi %r{{.*}}, 16
217*9880d681SAndroid Build Coastguard Worker; spill sret to stack
218*9880d681SAndroid Build Coastguard Worker; CHECK-O0: stg %r2, [[OFFS1:[0-9]+]](%r15)
219*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lgr %r2, %r{{.*}}
220*9880d681SAndroid Build Coastguard Worker; CHECK-O0: st %r3, [[OFFS2:[0-9]+]](%r15)
221*9880d681SAndroid Build Coastguard Worker; CHECK-O0: brasl %r14, malloc
222*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lgr {{.*}}, %r2
223*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mvi 8(%r2), 1
224*9880d681SAndroid Build Coastguard Worker; CHECK-O0-DAG: lg %r[[REG1:[0-9]+]], [[OFFS1]](%r15)
225*9880d681SAndroid Build Coastguard Worker; CHECK-O0-DAG: l %r[[REG2:[0-9]+]], [[OFFS2]](%r15)
226*9880d681SAndroid Build Coastguard Worker; CHECK-O0: st %r[[REG2]], 4(%r[[REG1]])
227*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lgr %r9, {{.*}}
228*9880d681SAndroid Build Coastguard Worker; CHECK-O0: br %r14
229*9880d681SAndroid Build Coastguard Workerentry:
230*9880d681SAndroid Build Coastguard Worker  %call = call i8* @malloc(i64 16)
231*9880d681SAndroid Build Coastguard Worker  %call.0 = bitcast i8* %call to %swift_error*
232*9880d681SAndroid Build Coastguard Worker  store %swift_error* %call.0, %swift_error** %error_ptr_ref
233*9880d681SAndroid Build Coastguard Worker  %tmp = getelementptr inbounds i8, i8* %call, i64 8
234*9880d681SAndroid Build Coastguard Worker  store i8 1, i8* %tmp
235*9880d681SAndroid Build Coastguard Worker  %v2 = getelementptr inbounds %struct.S, %struct.S* %agg.result, i32 0, i32 1
236*9880d681SAndroid Build Coastguard Worker  store i32 %val1, i32* %v2
237*9880d681SAndroid Build Coastguard Worker  ret void
238*9880d681SAndroid Build Coastguard Worker}
239*9880d681SAndroid Build Coastguard Worker
240*9880d681SAndroid Build Coastguard Worker; "caller3" calls "foo_sret" that takes a swifterror parameter.
241*9880d681SAndroid Build Coastguard Workerdefine float @caller3(i8* %error_ref) {
242*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: caller3:
243*9880d681SAndroid Build Coastguard Worker; Make a copy of error_ref because r2 is getting clobbered
244*9880d681SAndroid Build Coastguard Worker; CHECK: lgr %r[[REG1:[0-9]+]], %r2
245*9880d681SAndroid Build Coastguard Worker; CHECK: lhi %r3, 1
246*9880d681SAndroid Build Coastguard Worker; CHECK: lghi %r9, 0
247*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, foo_sret
248*9880d681SAndroid Build Coastguard Worker; CHECK: cgijlh %r9, 0,
249*9880d681SAndroid Build Coastguard Worker; Access part of the error object and save it to error_ref
250*9880d681SAndroid Build Coastguard Worker; CHECK: lb %r0, 8(%r9)
251*9880d681SAndroid Build Coastguard Worker; CHECK: stc %r0, 0(%r[[REG1]])
252*9880d681SAndroid Build Coastguard Worker; CHECK: lgr %r2, %r9
253*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, free
254*9880d681SAndroid Build Coastguard Worker
255*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: caller3:
256*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lghi %r9, 0
257*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lhi %r3, 1
258*9880d681SAndroid Build Coastguard Worker; CHECK-O0: stg %r2, {{.*}}(%r15)
259*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lgr %r2, {{.*}}
260*9880d681SAndroid Build Coastguard Worker; CHECK-O0: brasl %r14, foo_sret
261*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lgr {{.*}}, %r9
262*9880d681SAndroid Build Coastguard Worker; CHECK-O0: cghi %r9, 0
263*9880d681SAndroid Build Coastguard Worker; CHECK-O0: jlh
264*9880d681SAndroid Build Coastguard Worker; Access part of the error object and save it to error_ref
265*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lb %r0, 8(%r{{.*}})
266*9880d681SAndroid Build Coastguard Worker; CHECK-O0: stc %r0, 0(%r{{.*}})
267*9880d681SAndroid Build Coastguard Worker; reload from stack
268*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lg %r2, {{.*}}(%r15)
269*9880d681SAndroid Build Coastguard Worker; CHECK-O0: brasl %r14, free
270*9880d681SAndroid Build Coastguard Workerentry:
271*9880d681SAndroid Build Coastguard Worker  %s = alloca %struct.S, align 8
272*9880d681SAndroid Build Coastguard Worker  %error_ptr_ref = alloca swifterror %swift_error*
273*9880d681SAndroid Build Coastguard Worker  store %swift_error* null, %swift_error** %error_ptr_ref
274*9880d681SAndroid Build Coastguard Worker  call void @foo_sret(%struct.S* sret %s, i32 1, %swift_error** swifterror %error_ptr_ref)
275*9880d681SAndroid Build Coastguard Worker  %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref
276*9880d681SAndroid Build Coastguard Worker  %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null
277*9880d681SAndroid Build Coastguard Worker  %tmp = bitcast %swift_error* %error_from_foo to i8*
278*9880d681SAndroid Build Coastguard Worker  br i1 %had_error_from_foo, label %handler, label %cont
279*9880d681SAndroid Build Coastguard Workercont:
280*9880d681SAndroid Build Coastguard Worker  %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1
281*9880d681SAndroid Build Coastguard Worker  %t = load i8, i8* %v1
282*9880d681SAndroid Build Coastguard Worker  store i8 %t, i8* %error_ref
283*9880d681SAndroid Build Coastguard Worker  br label %handler
284*9880d681SAndroid Build Coastguard Workerhandler:
285*9880d681SAndroid Build Coastguard Worker  call void @free(i8* %tmp)
286*9880d681SAndroid Build Coastguard Worker  ret float 1.0
287*9880d681SAndroid Build Coastguard Worker}
288*9880d681SAndroid Build Coastguard Worker
289*9880d681SAndroid Build Coastguard Worker; This is a caller with multiple swifterror values, it calls "foo" twice, each
290*9880d681SAndroid Build Coastguard Worker; time with a different swifterror value, from "alloca swifterror".
291*9880d681SAndroid Build Coastguard Workerdefine float @caller_with_multiple_swifterror_values(i8* %error_ref, i8* %error_ref2) {
292*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: caller_with_multiple_swifterror_values:
293*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: lgr %r[[REG1:[0-9]+]], %r2
294*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: lgr %r[[REG2:[0-9]+]], %r3
295*9880d681SAndroid Build Coastguard Worker; The first swifterror value:
296*9880d681SAndroid Build Coastguard Worker; CHECK: lghi %r9, 0
297*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, foo
298*9880d681SAndroid Build Coastguard Worker; CHECK: cgijlh %r9, 0,
299*9880d681SAndroid Build Coastguard Worker; Access part of the error object and save it to error_ref
300*9880d681SAndroid Build Coastguard Worker; CHECK: lb %r0, 8(%r9)
301*9880d681SAndroid Build Coastguard Worker; CHECK: stc %r0, 0(%r[[REG1]])
302*9880d681SAndroid Build Coastguard Worker; CHECK: lgr %r2, %r9
303*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, free
304*9880d681SAndroid Build Coastguard Worker
305*9880d681SAndroid Build Coastguard Worker; The second swifterror value:
306*9880d681SAndroid Build Coastguard Worker; CHECK: lghi %r9, 0
307*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, foo
308*9880d681SAndroid Build Coastguard Worker; CHECK: cgijlh %r9, 0,
309*9880d681SAndroid Build Coastguard Worker; Access part of the error object and save it to error_ref
310*9880d681SAndroid Build Coastguard Worker; CHECK: lb %r0, 8(%r9)
311*9880d681SAndroid Build Coastguard Worker; CHECK: stc %r0, 0(%r[[REG2]])
312*9880d681SAndroid Build Coastguard Worker; CHECK: lgr %r2, %r9
313*9880d681SAndroid Build Coastguard Worker; CHECK: brasl %r14, free
314*9880d681SAndroid Build Coastguard Worker
315*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: caller_with_multiple_swifterror_values:
316*9880d681SAndroid Build Coastguard Worker
317*9880d681SAndroid Build Coastguard Worker; The first swifterror value:
318*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lghi %r9, 0
319*9880d681SAndroid Build Coastguard Worker; CHECK-O0: brasl %r14, foo
320*9880d681SAndroid Build Coastguard Worker; CHECK-O0: jlh
321*9880d681SAndroid Build Coastguard Worker
322*9880d681SAndroid Build Coastguard Worker; The second swifterror value:
323*9880d681SAndroid Build Coastguard Worker; CHECK-O0: lghi %r9, 0
324*9880d681SAndroid Build Coastguard Worker; CHECK-O0: brasl %r14, foo
325*9880d681SAndroid Build Coastguard Worker; CHECK-O0: jlh
326*9880d681SAndroid Build Coastguard Workerentry:
327*9880d681SAndroid Build Coastguard Worker  %error_ptr_ref = alloca swifterror %swift_error*
328*9880d681SAndroid Build Coastguard Worker  store %swift_error* null, %swift_error** %error_ptr_ref
329*9880d681SAndroid Build Coastguard Worker  %call = call float @foo(%swift_error** swifterror %error_ptr_ref)
330*9880d681SAndroid Build Coastguard Worker  %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref
331*9880d681SAndroid Build Coastguard Worker  %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null
332*9880d681SAndroid Build Coastguard Worker  %tmp = bitcast %swift_error* %error_from_foo to i8*
333*9880d681SAndroid Build Coastguard Worker  br i1 %had_error_from_foo, label %handler, label %cont
334*9880d681SAndroid Build Coastguard Workercont:
335*9880d681SAndroid Build Coastguard Worker  %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1
336*9880d681SAndroid Build Coastguard Worker  %t = load i8, i8* %v1
337*9880d681SAndroid Build Coastguard Worker  store i8 %t, i8* %error_ref
338*9880d681SAndroid Build Coastguard Worker  br label %handler
339*9880d681SAndroid Build Coastguard Workerhandler:
340*9880d681SAndroid Build Coastguard Worker  call void @free(i8* %tmp)
341*9880d681SAndroid Build Coastguard Worker
342*9880d681SAndroid Build Coastguard Worker  %error_ptr_ref2 = alloca swifterror %swift_error*
343*9880d681SAndroid Build Coastguard Worker  store %swift_error* null, %swift_error** %error_ptr_ref2
344*9880d681SAndroid Build Coastguard Worker  %call2 = call float @foo(%swift_error** swifterror %error_ptr_ref2)
345*9880d681SAndroid Build Coastguard Worker  %error_from_foo2 = load %swift_error*, %swift_error** %error_ptr_ref2
346*9880d681SAndroid Build Coastguard Worker  %had_error_from_foo2 = icmp ne %swift_error* %error_from_foo2, null
347*9880d681SAndroid Build Coastguard Worker  %bitcast2 = bitcast %swift_error* %error_from_foo2 to i8*
348*9880d681SAndroid Build Coastguard Worker  br i1 %had_error_from_foo2, label %handler2, label %cont2
349*9880d681SAndroid Build Coastguard Workercont2:
350*9880d681SAndroid Build Coastguard Worker  %v2 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo2, i64 0, i32 1
351*9880d681SAndroid Build Coastguard Worker  %t2 = load i8, i8* %v2
352*9880d681SAndroid Build Coastguard Worker  store i8 %t2, i8* %error_ref2
353*9880d681SAndroid Build Coastguard Worker  br label %handler2
354*9880d681SAndroid Build Coastguard Workerhandler2:
355*9880d681SAndroid Build Coastguard Worker  call void @free(i8* %bitcast2)
356*9880d681SAndroid Build Coastguard Worker
357*9880d681SAndroid Build Coastguard Worker  ret float 1.0
358*9880d681SAndroid Build Coastguard Worker}
359