Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / CSKY / csky-soft-abi.c
blob1aba2df1f20a28aeb470aeffcd798e5972cdc2cf
1 // RUN: %clang_cc1 -triple csky -target-feature +fpuv2_sf -target-feature +fpuv2_df -target-feature +hard-float -emit-llvm %s -o - | FileCheck %s
3 #include <stdint.h>
5 // Verify that the tracking of used GPRs and FPRs works correctly by checking
6 // that small integers are sign/zero extended when passed in registers.
8 // Doubles are passed in FPRs, so argument 'i' will be passed zero-extended
9 // because it will be passed in a GPR.
11 // CHECK: define{{.*}} void @f_fpr_tracking(double noundef %a, double noundef %b, double noundef %c, double noundef %d, i8 noundef zeroext %i)
12 void f_fpr_tracking(double a, double b, double c, double d, uint8_t i) {}
14 // A struct containing just one floating-point real is passed as though it
15 // were a standalone floating-point real.
16 struct double_s {
17 double f;
20 // CHECK: define{{.*}} void @f_double_s_arg(double %a.coerce)
21 void f_double_s_arg(struct double_s a) {}
23 // CHECK: define{{.*}} double @f_ret_double_s()
24 struct double_s f_ret_double_s(void) {
25 return (struct double_s){1.0};
28 // A struct containing a double and any number of zero-width bitfields is
29 // passed as though it were a standalone floating-point real.
31 struct zbf_double_s {
32 int : 0;
33 double f;
35 struct zbf_double_zbf_s {
36 int : 0;
37 double f;
38 int : 0;
41 // CHECK: define{{.*}} void @f_zbf_double_s_arg(double %a.coerce)
42 void f_zbf_double_s_arg(struct zbf_double_s a) {}
44 // CHECK: define{{.*}} double @f_ret_zbf_double_s()
45 struct zbf_double_s f_ret_zbf_double_s(void) {
46 return (struct zbf_double_s){1.0};
49 // CHECK: define{{.*}} void @f_zbf_double_zbf_s_arg(double %a.coerce)
50 void f_zbf_double_zbf_s_arg(struct zbf_double_zbf_s a) {}
52 // CHECK: define{{.*}} double @f_ret_zbf_double_zbf_s()
53 struct zbf_double_zbf_s f_ret_zbf_double_zbf_s(void) {
54 return (struct zbf_double_zbf_s){1.0};
57 // For argument type, the first 4*XLen parts of aggregate will be passed
58 // in registers, and the rest will be passed in stack.
59 // So we can coerce to integers directly and let backend handle it correctly.
60 // For return type, aggregate which <= 2*XLen will be returned in registers.
61 // Otherwise, aggregate will be returned indirectly.
63 struct double_double_s {
64 double f;
65 double g;
67 struct double_float_s {
68 double f;
69 float g;
72 // CHECK: define{{.*}} void @f_double_double_s_arg([4 x i32] %a.coerce)
73 void f_double_double_s_arg(struct double_double_s a) {}
75 // CHECK: define{{.*}} void @f_ret_double_double_s(ptr noalias sret(%struct.double_double_s) align 4 %agg.result)
76 struct double_double_s f_ret_double_double_s(void) {
77 return (struct double_double_s){1.0, 2.0};
80 // CHECK: define{{.*}} void @f_double_float_s_arg([3 x i32] %a.coerce)
81 void f_double_float_s_arg(struct double_float_s a) {}
83 // CHECK: define{{.*}} void @f_ret_double_float_s(ptr noalias sret(%struct.double_float_s) align 4 %agg.result)
84 struct double_float_s f_ret_double_float_s(void) {
85 return (struct double_float_s){1.0, 2.0};
88 // CHECK: define{{.*}} void @f_double_double_s_arg_insufficient_fprs(float noundef %a, double noundef %b, double noundef %c, double noundef %d, double noundef %e, double noundef %f, double noundef %g, double noundef %i, [4 x i32] %h.coerce)
89 void f_double_double_s_arg_insufficient_fprs(float a, double b, double c, double d,
90 double e, double f, double g, double i, struct double_double_s h) {}
92 struct double_int8_s {
93 double f;
94 int8_t i;
96 struct double_uint8_s {
97 double f;
98 uint8_t i;
100 struct double_int32_s {
101 double f;
102 int32_t i;
104 struct double_int64_s {
105 double f;
106 int64_t i;
108 struct double_int64bf_s {
109 double f;
110 int64_t i : 32;
112 struct double_int8_zbf_s {
113 double f;
114 int8_t i;
115 int : 0;
118 // CHECK: define{{.*}} @f_double_int8_s_arg([3 x i32] %a.coerce)
119 void f_double_int8_s_arg(struct double_int8_s a) {}
121 // CHECK: define{{.*}} void @f_ret_double_int8_s(ptr noalias sret(%struct.double_int8_s) align 4 %agg.result)
122 struct double_int8_s f_ret_double_int8_s(void) {
123 return (struct double_int8_s){1.0, 2};
126 // CHECK: define{{.*}} void @f_double_uint8_s_arg([3 x i32] %a.coerce)
127 void f_double_uint8_s_arg(struct double_uint8_s a) {}
129 // CHECK: define{{.*}} void @f_ret_double_uint8_s(ptr noalias sret(%struct.double_uint8_s) align 4 %agg.result)
130 struct double_uint8_s f_ret_double_uint8_s(void) {
131 return (struct double_uint8_s){1.0, 2};
134 // CHECK: define{{.*}} void @f_double_int32_s_arg([3 x i32] %a.coerce)
135 void f_double_int32_s_arg(struct double_int32_s a) {}
137 // CHECK: define{{.*}} void @f_ret_double_int32_s(ptr noalias sret(%struct.double_int32_s) align 4 %agg.result)
138 struct double_int32_s f_ret_double_int32_s(void) {
139 return (struct double_int32_s){1.0, 2};
142 // CHECK: define{{.*}} void @f_double_int64_s_arg([4 x i32] %a.coerce)
143 void f_double_int64_s_arg(struct double_int64_s a) {}
145 // CHECK: define{{.*}} void @f_ret_double_int64_s(ptr noalias sret(%struct.double_int64_s) align 4 %agg.result)
146 struct double_int64_s f_ret_double_int64_s(void) {
147 return (struct double_int64_s){1.0, 2};
150 // CHECK: define{{.*}} void @f_double_int64bf_s_arg([3 x i32] %a.coerce)
151 void f_double_int64bf_s_arg(struct double_int64bf_s a) {}
153 // CHECK: define{{.*}} void @f_ret_double_int64bf_s(ptr noalias sret(%struct.double_int64bf_s) align 4 %agg.result)
154 struct double_int64bf_s f_ret_double_int64bf_s(void) {
155 return (struct double_int64bf_s){1.0, 2};
158 // CHECK: define{{.*}} void @f_double_int8_zbf_s([3 x i32] %a.coerce)
159 void f_double_int8_zbf_s(struct double_int8_zbf_s a) {}
161 // CHECK: define{{.*}} void @f_ret_double_int8_zbf_s(ptr noalias sret(%struct.double_int8_zbf_s) align 4 %agg.result)
162 struct double_int8_zbf_s f_ret_double_int8_zbf_s(void) {
163 return (struct double_int8_zbf_s){1.0, 2};
166 // CHECK: define{{.*}} void @f_double_int8_s_arg_insufficient_gprs(i32 noundef %a, i32 noundef %b, i32 noundef %c, i32 noundef %d, i32 noundef %e, i32 noundef %f, i32 noundef %g, i32 noundef %h, [3 x i32] %i.coerce)
167 void f_double_int8_s_arg_insufficient_gprs(int a, int b, int c, int d, int e,
168 int f, int g, int h, struct double_int8_s i) {}
170 // CHECK: define{{.*}} void @f_struct_double_int8_insufficient_fprs(float noundef %a, double noundef %b, double noundef %c, double noundef %d, double noundef %e, double noundef %f, double noundef %g, double noundef %h, [3 x i32] %i.coerce)
171 void f_struct_double_int8_insufficient_fprs(float a, double b, double c, double d,
172 double e, double f, double g, double h, struct double_int8_s i) {}
174 // Complex floating-point values are special in passing argument,
175 // and it's not same as structs containing a single complex.
176 // Complex floating-point value should be passed in two consecutive fprs.
177 // But the return process is same as struct.
179 // But now we test in soft-float, it's coerced and passing in gprs.
180 // CHECK: define{{.*}} void @f_doublecomplex([4 x i32] noundef %a.coerce)
181 void f_doublecomplex(double __complex__ a) {}
183 // CHECK: define{{.*}} void @f_ret_doublecomplex(ptr noalias sret({ double, double }) align 4 %agg.result)
184 double __complex__ f_ret_doublecomplex(void) {
185 return 1.0;
188 struct doublecomplex_s {
189 double __complex__ c;
192 // CHECK: define{{.*}} void @f_doublecomplex_s_arg([4 x i32] %a.coerce)
193 void f_doublecomplex_s_arg(struct doublecomplex_s a) {}
195 // CHECK: define{{.*}} void @f_ret_doublecomplex_s(ptr noalias sret(%struct.doublecomplex_s) align 4 %agg.result)
196 struct doublecomplex_s f_ret_doublecomplex_s(void) {
197 return (struct doublecomplex_s){1.0};
200 // Test single or two-element structs that need flattening. e.g. those
201 // containing nested structs, doubles in small arrays, zero-length structs etc.
203 struct doublearr1_s {
204 double a[1];
207 // CHECK: define{{.*}} void @f_doublearr1_s_arg(double %a.coerce)
208 void f_doublearr1_s_arg(struct doublearr1_s a) {}
210 // CHECK: define{{.*}} double @f_ret_doublearr1_s()
211 struct doublearr1_s f_ret_doublearr1_s(void) {
212 return (struct doublearr1_s){{1.0}};
215 struct doublearr2_s {
216 double a[2];
219 // CHECK: define{{.*}} void @f_doublearr2_s_arg([4 x i32] %a.coerce)
220 void f_doublearr2_s_arg(struct doublearr2_s a) {}
222 // CHECK: define{{.*}} void @f_ret_doublearr2_s(ptr noalias sret(%struct.doublearr2_s) align 4 %agg.result)
223 struct doublearr2_s f_ret_doublearr2_s(void) {
224 return (struct doublearr2_s){{1.0, 2.0}};
227 struct doublearr2_tricky1_s {
228 struct {
229 double f[1];
230 } g[2];
233 // CHECK: define{{.*}} void @f_doublearr2_tricky1_s_arg([4 x i32] %a.coerce)
234 void f_doublearr2_tricky1_s_arg(struct doublearr2_tricky1_s a) {}
236 // CHECK: define{{.*}} void @f_ret_doublearr2_tricky1_s(ptr noalias sret(%struct.doublearr2_tricky1_s) align 4 %agg.result)
237 struct doublearr2_tricky1_s f_ret_doublearr2_tricky1_s(void) {
238 return (struct doublearr2_tricky1_s){{{{1.0}}, {{2.0}}}};
241 struct doublearr2_tricky2_s {
242 struct {};
243 struct {
244 double f[1];
245 } g[2];
248 // CHECK: define{{.*}} void @f_doublearr2_tricky2_s_arg([4 x i32] %a.coerce)
249 void f_doublearr2_tricky2_s_arg(struct doublearr2_tricky2_s a) {}
251 // CHECK: define{{.*}} void @f_ret_doublearr2_tricky2_s(ptr noalias sret(%struct.doublearr2_tricky2_s) align 4 %agg.result)
252 struct doublearr2_tricky2_s f_ret_doublearr2_tricky2_s(void) {
253 return (struct doublearr2_tricky2_s){{}, {{{1.0}}, {{2.0}}}};
256 struct doublearr2_tricky3_s {
257 union {};
258 struct {
259 double f[1];
260 } g[2];
263 // CHECK: define{{.*}} void @f_doublearr2_tricky3_s_arg([4 x i32] %a.coerce)
264 void f_doublearr2_tricky3_s_arg(struct doublearr2_tricky3_s a) {}
266 // CHECK: define{{.*}} void @f_ret_doublearr2_tricky3_s(ptr noalias sret(%struct.doublearr2_tricky3_s) align 4 %agg.result)
267 struct doublearr2_tricky3_s f_ret_doublearr2_tricky3_s(void) {
268 return (struct doublearr2_tricky3_s){{}, {{{1.0}}, {{2.0}}}};
271 struct doublearr2_tricky4_s {
272 union {};
273 struct {
274 struct {};
275 double f[1];
276 } g[2];
279 // CHECK: define{{.*}} void @f_doublearr2_tricky4_s_arg([4 x i32] %a.coerce)
280 void f_doublearr2_tricky4_s_arg(struct doublearr2_tricky4_s a) {}
282 // CHECK: define{{.*}} void @f_ret_doublearr2_tricky4_s(ptr noalias sret(%struct.doublearr2_tricky4_s) align 4 %agg.result)
283 struct doublearr2_tricky4_s f_ret_doublearr2_tricky4_s(void) {
284 return (struct doublearr2_tricky4_s){{}, {{{}, {1.0}}, {{}, {2.0}}}};
287 struct int_double_int_s {
288 int a;
289 double b;
290 int c;
293 // CHECK: define{{.*}} void @f_int_double_int_s_arg([4 x i32] %a.coerce)
294 void f_int_double_int_s_arg(struct int_double_int_s a) {}
296 // CHECK: define{{.*}} void @f_ret_int_double_int_s(ptr noalias sret(%struct.int_double_int_s) align 4 %agg.result)
297 struct int_double_int_s f_ret_int_double_int_s(void) {
298 return (struct int_double_int_s){1, 2.0, 3};
301 struct int64_double_s {
302 int64_t a;
303 double b;
306 // CHECK: define{{.*}} void @f_int64_double_s_arg([4 x i32] %a.coerce)
307 void f_int64_double_s_arg(struct int64_double_s a) {}
309 // CHECK: define{{.*}} void @f_ret_int64_double_s(ptr noalias sret(%struct.int64_double_s) align 4 %agg.result)
310 struct int64_double_s f_ret_int64_double_s(void) {
311 return (struct int64_double_s){1, 2.0};
314 struct char_char_double_s {
315 char a;
316 char b;
317 double c;
320 // CHECK-LABEL: define{{.*}} void @f_char_char_double_s_arg([3 x i32] %a.coerce)
321 void f_char_char_double_s_arg(struct char_char_double_s a) {}
323 // CHECK: define{{.*}} void @f_ret_char_char_double_s(ptr noalias sret(%struct.char_char_double_s) align 4 %agg.result)
324 struct char_char_double_s f_ret_char_char_double_s(void) {
325 return (struct char_char_double_s){1, 2, 3.0};
328 // A union containing just one floating-point real can not be passed as though it
329 // were a standalone floating-point real.
330 union double_u {
331 double a;
334 // CHECK: define{{.*}} void @f_double_u_arg([2 x i32] %a.coerce)
335 void f_double_u_arg(union double_u a) {}
337 // CHECK: define{{.*}} [2 x i32] @f_ret_double_u()
338 union double_u f_ret_double_u(void) {
339 return (union double_u){1.0};
342 // CHECK: define{{.*}} void @f_ret_double_int32_s_double_int32_s_just_sufficient_gprs(ptr noalias sret(%struct.double_int32_s) align 4 %agg.result, i32 noundef %a, i32 noundef %b, i32 noundef %c, i32 noundef %d, i32 noundef %e, i32 noundef %f, i32 noundef %g, [3 x i32] %h.coerce)
343 struct double_int32_s f_ret_double_int32_s_double_int32_s_just_sufficient_gprs(
344 int a, int b, int c, int d, int e, int f, int g, struct double_int32_s h) {
345 return (struct double_int32_s){1.0, 2};
348 // CHECK: define{{.*}} void @f_ret_double_double_s_double_int32_s_just_sufficient_gprs(ptr noalias sret(%struct.double_double_s) align 4 %agg.result, i32 noundef %a, i32 noundef %b, i32 noundef %c, i32 noundef %d, i32 noundef %e, i32 noundef %f, i32 noundef %g, [3 x i32] %h.coerce)
349 struct double_double_s f_ret_double_double_s_double_int32_s_just_sufficient_gprs(
350 int a, int b, int c, int d, int e, int f, int g, struct double_int32_s h) {
351 return (struct double_double_s){1.0, 2.0};
354 // CHECK: define{{.*}} void @f_ret_doublecomplex_double_int32_s_just_sufficient_gprs(ptr noalias sret({ double, double }) align 4 %agg.result, i32 noundef %a, i32 noundef %b, i32 noundef %c, i32 noundef %d, i32 noundef %e, i32 noundef %f, i32 noundef %g, [3 x i32] %h.coerce)
355 double __complex__ f_ret_doublecomplex_double_int32_s_just_sufficient_gprs(
356 int a, int b, int c, int d, int e, int f, int g, struct double_int32_s h) {
357 return 1.0;
360 struct tiny {
361 uint8_t a, b, c, d;
364 struct small {
365 int32_t a, *b;
368 struct small_aligned {
369 int64_t a;
372 struct large {
373 int32_t a, b, c, d;
376 // Ensure that scalars passed on the stack are still determined correctly in
377 // the presence of large return values that consume a register due to the need
378 // to pass a pointer.
380 // CHECK-LABEL: define{{.*}} void @f_scalar_stack_2(ptr noalias sret(%struct.large) align 4 %agg.result, float noundef %a, i64 noundef %b, double noundef %c, double noundef %d, i8 noundef zeroext %e, i8 noundef signext %f, i8 noundef zeroext %g)
381 struct large f_scalar_stack_2(float a, int64_t b, double c, long double d,
382 uint8_t e, int8_t f, uint8_t g) {
383 return (struct large){a, e, f, g};
386 // Aggregates and >=XLen scalars passed on the stack should be lowered just as
387 // they would be if passed via registers.
389 // CHECK-LABEL: define{{.*}} void @f_scalar_stack_3(double noundef %a, i64 noundef %b, double noundef %c, i64 noundef %d, i32 noundef %e, i64 noundef %f, float noundef %g, double noundef %h, double noundef %i)
390 void f_scalar_stack_3(double a, int64_t b, double c, int64_t d, int e,
391 int64_t f, float g, double h, long double i) {}
393 // CHECK-LABEL: define{{.*}} void @f_agg_stack(double noundef %a, i64 noundef %b, double noundef %c, i64 noundef %d, i32 %e.coerce, [2 x i32] %f.coerce, i64 %g.coerce, [4 x i32] %h.coerce)
394 void f_agg_stack(double a, int64_t b, double c, int64_t d, struct tiny e,
395 struct small f, struct small_aligned g, struct large h) {}