1f79470583759d20c20268711e6111461aefa8461Jim Grosbach// REQUIRES: arm-registered-target
2194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson// RUN: %clang_cc1 -triple thumbv7-apple-darwin9 \
3194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson// RUN:   -target-abi aapcs \
4194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson// RUN:   -target-cpu cortex-a8 \
5194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson// RUN:   -mfloat-abi hard \
6194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson// RUN:   -ffreestanding \
7194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson// RUN:   -emit-llvm -w -o - %s | FileCheck %s
8194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson
97da46f949f6ec63d7c7dcda5f49588261c669ffbDerek Schuff// RUN: %clang_cc1 -triple armv7-unknown-nacl-gnueabi \
107da46f949f6ec63d7c7dcda5f49588261c669ffbDerek Schuff// RUN:  -target-cpu cortex-a8 \
117da46f949f6ec63d7c7dcda5f49588261c669ffbDerek Schuff// RUN:  -mfloat-abi hard \
127da46f949f6ec63d7c7dcda5f49588261c669ffbDerek Schuff// RUN:  -ffreestanding \
137da46f949f6ec63d7c7dcda5f49588261c669ffbDerek Schuff// RUN:  -emit-llvm -w -o - %s | FileCheck %s
147da46f949f6ec63d7c7dcda5f49588261c669ffbDerek Schuff
156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// RUN: %clang_cc1 -triple arm64-apple-darwin9 -target-feature +neon \
16651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN:   -ffreestanding \
17651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN:   -emit-llvm -w -o - %s | FileCheck -check-prefix=CHECK64 %s
18651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
19651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#ifdef __arm64__
20651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#include <arm_neon.h>
21651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#else
22194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson#include <arm_neon.h>
23651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#endif
24194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson
25194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonstruct homogeneous_struct {
26194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  float f[2];
27194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  float f3;
28194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  float f4;
29194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson};
306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: define arm_aapcs_vfpcc %struct.homogeneous_struct @test_struct(%struct.homogeneous_struct %{{.*}})
31651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK64: define %struct.homogeneous_struct @test_struct(float %{{.*}}, float %{{.*}}, float %{{.*}}, float %{{.*}})
323b694fab31d3a7a8379996cbe7ef8d53f7d677bcBob Wilsonextern struct homogeneous_struct struct_callee(struct homogeneous_struct);
333b694fab31d3a7a8379996cbe7ef8d53f7d677bcBob Wilsonstruct homogeneous_struct test_struct(struct homogeneous_struct arg) {
343b694fab31d3a7a8379996cbe7ef8d53f7d677bcBob Wilson  return struct_callee(arg);
35194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson}
36194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson
376bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: define arm_aapcs_vfpcc void @test_struct_variadic(%struct.homogeneous_struct* {{.*}}, ...)
38651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstruct homogeneous_struct test_struct_variadic(struct homogeneous_struct arg, ...) {
39651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  return struct_callee(arg);
40651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines}
41651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
42194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonstruct nested_array {
43194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  double d[4];
44194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson};
456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: define arm_aapcs_vfpcc void @test_array(%struct.nested_array %{{.*}})
46651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK64: define void @test_array(double %{{.*}}, double %{{.*}}, double %{{.*}}, double %{{.*}})
47194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonextern void array_callee(struct nested_array);
48194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonvoid test_array(struct nested_array arg) {
49194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  array_callee(arg);
50194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson}
51194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson
52194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonextern void complex_callee(__complex__ double);
536bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: define arm_aapcs_vfpcc void @test_complex({ double, double } %{{.*}})
54651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK64: define void @test_complex(double %{{.*}}, double %{{.*}})
55194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonvoid test_complex(__complex__ double cd) {
56194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  complex_callee(cd);
57194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson}
58194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson
59adfa45ffd67d1959cb1ff8cec88ad2ff3ffb7798Tim Northover// Long double is the same as double on AAPCS, it should be homogeneous.
60adfa45ffd67d1959cb1ff8cec88ad2ff3ffb7798Tim Northoverextern void complex_long_callee(__complex__ long double);
616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: define arm_aapcs_vfpcc void @test_complex_long({ double, double } %{{.*}})
62adfa45ffd67d1959cb1ff8cec88ad2ff3ffb7798Tim Northovervoid test_complex_long(__complex__ long double cd) {
63adfa45ffd67d1959cb1ff8cec88ad2ff3ffb7798Tim Northover  complex_callee(cd);
64adfa45ffd67d1959cb1ff8cec88ad2ff3ffb7798Tim Northover}
65adfa45ffd67d1959cb1ff8cec88ad2ff3ffb7798Tim Northover
66194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson// Structs with more than 4 elements of the base type are not treated
67194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson// as homogeneous aggregates.  Test that.
68194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson
69194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonstruct big_struct {
70194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  float f1;
71194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  float f[2];
72194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  float f3;
73194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  float f4;
74194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson};
756bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: define arm_aapcs_vfpcc void @test_big({ [5 x i32] } %{{.*}})
76651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK64: define void @test_big(%struct.big_struct* %{{.*}})
77651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK64: call void @llvm.memcpy
78651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK64: call void @big_callee(%struct.big_struct*
79194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonextern void big_callee(struct big_struct);
80194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonvoid test_big(struct big_struct arg) {
81194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  big_callee(arg);
82194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson}
83194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson
84194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson// Make sure that aggregates with multiple base types are not treated as
85194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson// homogeneous aggregates.
86194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson
87194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonstruct heterogeneous_struct {
88194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  float f1;
89194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  int i2;
90194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson};
916bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: define arm_aapcs_vfpcc void @test_hetero({ [2 x i32] } %{{.*}})
92651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK64: define void @test_hetero(i64 %{{.*}})
93194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonextern void hetero_callee(struct heterogeneous_struct);
94194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonvoid test_hetero(struct heterogeneous_struct arg) {
95194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  hetero_callee(arg);
96194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson}
97194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson
98194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson// Neon multi-vector types are homogeneous aggregates.
996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: define arm_aapcs_vfpcc <16 x i8> @f0(%struct.int8x16x4_t %{{.*}})
100651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK64: define <16 x i8> @f0(<16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <16 x i8> %{{.*}})
101194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonint8x16_t f0(int8x16x4_t v4) {
102194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  return vaddq_s8(v4.val[0], v4.val[3]);
103194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson}
104194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson
105194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson// ...and it doesn't matter whether the vectors are exactly the same, as long
106194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson// as they have the same size.
107194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson
108194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonstruct neon_struct {
109194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  int8x8x2_t v12;
110194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  int32x2_t v3;
111194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  int16x4_t v4;
112194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson};
1136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: define arm_aapcs_vfpcc void @test_neon(%struct.neon_struct %{{.*}})
114651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK64: define void @test_neon(<8 x i8> %{{.*}}, <8 x i8> %{{.*}}, <2 x i32> %{{.*}}, <4 x i16> %{{.*}})
115194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonextern void neon_callee(struct neon_struct);
116194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilsonvoid test_neon(struct neon_struct arg) {
117194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson  neon_callee(arg);
118194f06a476d299a7a70e5ff1d152f5895dc0a76cBob Wilson}
119634b3d26969f139a25b223074567ba5ab7ba7dd9Manman Ren
120651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK-LABEL: define arm_aapcs_vfpcc void @f33(%struct.s33* byval align 1 %s)
121634b3d26969f139a25b223074567ba5ab7ba7dd9Manman Renstruct s33 { char buf[32*32]; };
122634b3d26969f139a25b223074567ba5ab7ba7dd9Manman Renvoid f33(struct s33 s) { }
123651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
124651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinestypedef struct { long long x; int y; } struct_long_long_int;
125651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// 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)
126651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid 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) {}
127651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
1286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// 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)
129651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid 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) {}
130651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
1316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// 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)
132651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstruct_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) {}
1336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
1346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestypedef struct { int a; int b:4; int c; } struct_int_bitfield_int;
1356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// 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)
1366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid 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) {}
1376bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
1386bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Note: this struct requires internal padding
1396bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinestypedef struct { int x; long long y; } struct_int_long_long;
1406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// 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)
1416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid 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) {}
142ef8225444452a1486bd721f3285301fe84643b00Stephen Hines
143ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// This very large struct (passed byval) uses up the GPRs, so no padding is needed
144ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestypedef struct { int x[17]; } struct_seventeen_ints;
145ef8225444452a1486bd721f3285301fe84643b00Stephen Hinestypedef struct { int x[4]; } struct_four_ints;
146ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// 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)
147ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesvoid 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