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