xref: /aosp_15_r20/external/clang/test/CodeGen/arm-aapcs-vfp.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // REQUIRES: arm-registered-target
2*67e74705SXin Li // REQUIRES: aarch64-registered-target
3*67e74705SXin Li // RUN: %clang_cc1 -triple thumbv7-apple-darwin9 \
4*67e74705SXin Li // RUN:   -target-abi aapcs \
5*67e74705SXin Li // RUN:   -target-cpu cortex-a8 \
6*67e74705SXin Li // RUN:   -mfloat-abi hard \
7*67e74705SXin Li // RUN:   -ffreestanding \
8*67e74705SXin Li // RUN:   -emit-llvm -w -o - %s | FileCheck %s
9*67e74705SXin Li 
10*67e74705SXin Li // RUN: %clang_cc1 -triple armv7-unknown-nacl-gnueabi \
11*67e74705SXin Li // RUN:  -target-cpu cortex-a8 \
12*67e74705SXin Li // RUN:  -mfloat-abi hard \
13*67e74705SXin Li // RUN:  -ffreestanding \
14*67e74705SXin Li // RUN:  -emit-llvm -w -o - %s | FileCheck %s
15*67e74705SXin Li 
16*67e74705SXin Li // RUN: %clang_cc1 -triple arm64-apple-darwin9 -target-feature +neon \
17*67e74705SXin Li // RUN:   -ffreestanding \
18*67e74705SXin Li // RUN:   -emit-llvm -w -o - %s | FileCheck -check-prefix=CHECK64 %s
19*67e74705SXin Li 
20*67e74705SXin Li #ifdef __arm64__
21*67e74705SXin Li #include <arm_neon.h>
22*67e74705SXin Li #else
23*67e74705SXin Li #include <arm_neon.h>
24*67e74705SXin Li #endif
25*67e74705SXin Li 
26*67e74705SXin Li struct homogeneous_struct {
27*67e74705SXin Li   float f[2];
28*67e74705SXin Li   float f3;
29*67e74705SXin Li   float f4;
30*67e74705SXin Li };
31*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc %struct.homogeneous_struct @test_struct(%struct.homogeneous_struct %{{.*}})
32*67e74705SXin Li // CHECK64: define %struct.homogeneous_struct @test_struct([4 x float] %{{.*}})
33*67e74705SXin Li extern struct homogeneous_struct struct_callee(struct homogeneous_struct);
test_struct(struct homogeneous_struct arg)34*67e74705SXin Li struct homogeneous_struct test_struct(struct homogeneous_struct arg) {
35*67e74705SXin Li   return struct_callee(arg);
36*67e74705SXin Li }
37*67e74705SXin Li 
38*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_struct_variadic(%struct.homogeneous_struct* {{.*}}, ...)
test_struct_variadic(struct homogeneous_struct arg,...)39*67e74705SXin Li struct homogeneous_struct test_struct_variadic(struct homogeneous_struct arg, ...) {
40*67e74705SXin Li   return struct_callee(arg);
41*67e74705SXin Li }
42*67e74705SXin Li 
43*67e74705SXin Li struct nested_array {
44*67e74705SXin Li   double d[4];
45*67e74705SXin Li };
46*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_array(%struct.nested_array %{{.*}})
47*67e74705SXin Li // CHECK64: define void @test_array([4 x double] %{{.*}})
48*67e74705SXin Li extern void array_callee(struct nested_array);
test_array(struct nested_array arg)49*67e74705SXin Li void test_array(struct nested_array arg) {
50*67e74705SXin Li   array_callee(arg);
51*67e74705SXin Li }
52*67e74705SXin Li 
53*67e74705SXin Li extern void complex_callee(__complex__ double);
54*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_complex({ double, double } %{{.*}})
55*67e74705SXin Li // CHECK64: define void @test_complex([2 x double] %cd.coerce)
test_complex(__complex__ double cd)56*67e74705SXin Li void test_complex(__complex__ double cd) {
57*67e74705SXin Li   complex_callee(cd);
58*67e74705SXin Li }
59*67e74705SXin Li 
60*67e74705SXin Li // Long double is the same as double on AAPCS, it should be homogeneous.
61*67e74705SXin Li extern void complex_long_callee(__complex__ long double);
62*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_complex_long({ double, double } %{{.*}})
test_complex_long(__complex__ long double cd)63*67e74705SXin Li void test_complex_long(__complex__ long double cd) {
64*67e74705SXin Li   complex_callee(cd);
65*67e74705SXin Li }
66*67e74705SXin Li 
67*67e74705SXin Li // Structs with more than 4 elements of the base type are not treated
68*67e74705SXin Li // as homogeneous aggregates.  Test that.
69*67e74705SXin Li 
70*67e74705SXin Li struct big_struct {
71*67e74705SXin Li   float f1;
72*67e74705SXin Li   float f[2];
73*67e74705SXin Li   float f3;
74*67e74705SXin Li   float f4;
75*67e74705SXin Li };
76*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_big([5 x i32] %{{.*}})
77*67e74705SXin Li // CHECK64: define void @test_big(%struct.big_struct* %{{.*}})
78*67e74705SXin Li // CHECK64: call void @llvm.memcpy
79*67e74705SXin Li // CHECK64: call void @big_callee(%struct.big_struct*
80*67e74705SXin Li extern void big_callee(struct big_struct);
test_big(struct big_struct arg)81*67e74705SXin Li void test_big(struct big_struct arg) {
82*67e74705SXin Li   big_callee(arg);
83*67e74705SXin Li }
84*67e74705SXin Li 
85*67e74705SXin Li // Make sure that aggregates with multiple base types are not treated as
86*67e74705SXin Li // homogeneous aggregates.
87*67e74705SXin Li 
88*67e74705SXin Li struct heterogeneous_struct {
89*67e74705SXin Li   float f1;
90*67e74705SXin Li   int i2;
91*67e74705SXin Li };
92*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_hetero([2 x i32] %{{.*}})
93*67e74705SXin Li // CHECK64: define void @test_hetero(i64 %{{.*}})
94*67e74705SXin Li extern void hetero_callee(struct heterogeneous_struct);
test_hetero(struct heterogeneous_struct arg)95*67e74705SXin Li void test_hetero(struct heterogeneous_struct arg) {
96*67e74705SXin Li   hetero_callee(arg);
97*67e74705SXin Li }
98*67e74705SXin Li 
99*67e74705SXin Li // Neon multi-vector types are homogeneous aggregates.
100*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc <16 x i8> @f0(%struct.int8x16x4_t %{{.*}})
101*67e74705SXin Li // CHECK64: define <16 x i8> @f0([4 x <16 x i8>] %{{.*}})
f0(int8x16x4_t v4)102*67e74705SXin Li int8x16_t f0(int8x16x4_t v4) {
103*67e74705SXin Li   return vaddq_s8(v4.val[0], v4.val[3]);
104*67e74705SXin Li }
105*67e74705SXin Li 
106*67e74705SXin Li // ...and it doesn't matter whether the vectors are exactly the same, as long
107*67e74705SXin Li // as they have the same size.
108*67e74705SXin Li 
109*67e74705SXin Li struct neon_struct {
110*67e74705SXin Li   int8x8x2_t v12;
111*67e74705SXin Li   int32x2_t v3;
112*67e74705SXin Li   int16x4_t v4;
113*67e74705SXin Li };
114*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_neon(%struct.neon_struct %{{.*}})
115*67e74705SXin Li // CHECK64: define void @test_neon([4 x <8 x i8>] %{{.*}})
116*67e74705SXin Li extern void neon_callee(struct neon_struct);
test_neon(struct neon_struct arg)117*67e74705SXin Li void test_neon(struct neon_struct arg) {
118*67e74705SXin Li   neon_callee(arg);
119*67e74705SXin Li }
120*67e74705SXin Li 
121*67e74705SXin Li // CHECK-LABEL: define arm_aapcs_vfpcc void @f33(%struct.s33* byval align 4 %s)
122*67e74705SXin Li struct s33 { char buf[32*32]; };
f33(struct s33 s)123*67e74705SXin Li void f33(struct s33 s) { }
124*67e74705SXin Li 
125*67e74705SXin Li typedef struct { long long x; int y; } struct_long_long_int;
126*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_vfp_stack_gpr_split_1(double %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, i32 %j, i64 %k, i32 %l)
test_vfp_stack_gpr_split_1(double a,double b,double c,double d,double e,double f,double g,double h,double i,int j,long long k,int l)127*67e74705SXin Li void test_vfp_stack_gpr_split_1(double a, double b, double c, double d, double e, double f, double g, double h, double i, int j, long long k, int l) {}
128*67e74705SXin Li 
129*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_vfp_stack_gpr_split_2(double %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, i32 %j, [2 x i64] %k.coerce)
test_vfp_stack_gpr_split_2(double a,double b,double c,double d,double e,double f,double g,double h,double i,int j,struct_long_long_int k)130*67e74705SXin Li void test_vfp_stack_gpr_split_2(double a, double b, double c, double d, double e, double f, double g, double h, double i, int j, struct_long_long_int k) {}
131*67e74705SXin Li 
132*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_vfp_stack_gpr_split_3(%struct.struct_long_long_int* noalias sret %agg.result, double %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, [2 x i64] %k.coerce)
test_vfp_stack_gpr_split_3(double a,double b,double c,double d,double e,double f,double g,double h,double i,struct_long_long_int k)133*67e74705SXin Li struct_long_long_int test_vfp_stack_gpr_split_3(double a, double b, double c, double d, double e, double f, double g, double h, double i, struct_long_long_int k) {}
134*67e74705SXin Li 
135*67e74705SXin Li typedef struct { int a; int b:4; int c; } struct_int_bitfield_int;
136*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_test_vfp_stack_gpr_split_bitfield(double %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, i32 %j, i32 %k, [3 x i32] %l.coerce)
test_test_vfp_stack_gpr_split_bitfield(double a,double b,double c,double d,double e,double f,double g,double h,double i,int j,int k,struct_int_bitfield_int l)137*67e74705SXin Li void test_test_vfp_stack_gpr_split_bitfield(double a, double b, double c, double d, double e, double f, double g, double h, double i, int j, int k, struct_int_bitfield_int l) {}
138*67e74705SXin Li 
139*67e74705SXin Li // Note: this struct requires internal padding
140*67e74705SXin Li typedef struct { int x; long long y; } struct_int_long_long;
141*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_vfp_stack_gpr_split_4(double %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, i32 %j, [2 x i64] %k.coerce)
test_vfp_stack_gpr_split_4(double a,double b,double c,double d,double e,double f,double g,double h,double i,int j,struct_int_long_long k)142*67e74705SXin Li void test_vfp_stack_gpr_split_4(double a, double b, double c, double d, double e, double f, double g, double h, double i, int j, struct_int_long_long k) {}
143*67e74705SXin Li 
144*67e74705SXin Li // This very large struct (passed byval) uses up the GPRs, so no padding is needed
145*67e74705SXin Li typedef struct { int x[17]; } struct_seventeen_ints;
146*67e74705SXin Li typedef struct { int x[4]; } struct_four_ints;
147*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_vfp_stack_gpr_split_5(%struct.struct_seventeen_ints* byval align 4 %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, double %j, [4 x i32] %k.coerce)
test_vfp_stack_gpr_split_5(struct_seventeen_ints a,double b,double c,double d,double e,double f,double g,double h,double i,double j,struct_four_ints k)148*67e74705SXin Li void test_vfp_stack_gpr_split_5(struct_seventeen_ints a, double b, double c, double d, double e, double f, double g, double h, double i, double j, struct_four_ints k) {}
149*67e74705SXin Li 
150*67e74705SXin Li // Here, parameter k would need padding to prevent it from being split, but it
151*67e74705SXin Li // is passed ByVal (due to being > 64 bytes), so the backend handles this instead.
test_vfp_stack_gpr_split_6(double a,double b,double c,double d,double e,double f,double g,double h,double i,int j,struct_seventeen_ints k)152*67e74705SXin Li void test_vfp_stack_gpr_split_6(double a, double b, double c, double d, double e, double f, double g, double h, double i, int j, struct_seventeen_ints k) {}
153*67e74705SXin Li // CHECK: define arm_aapcs_vfpcc void @test_vfp_stack_gpr_split_6(double %a, double %b, double %c, double %d, double %e, double %f, double %g, double %h, double %i, i32 %j, %struct.struct_seventeen_ints* byval align 4 %k)
154