]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGen/64bit-swiftcall.c
Vendor import of clang trunk r304149:
[FreeBSD/FreeBSD.git] / test / CodeGen / 64bit-swiftcall.c
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
3 // RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM64
4
5 // REQUIRES: aarch64-registered-target,x86-registered-target
6
7 #define SWIFTCALL __attribute__((swiftcall))
8 #define OUT __attribute__((swift_indirect_result))
9 #define ERROR __attribute__((swift_error_result))
10 #define CONTEXT __attribute__((swift_context))
11
12 // CHECK: [[STRUCT2_RESULT:@.*]] = private {{.*}} constant [[STRUCT2_TYPE:%.*]] { i32 0, i8 0, i8 undef, i8 0, float 0.000000e+00, float 0.000000e+00 }
13
14 /*****************************************************************************/
15 /****************************** PARAMETER ABIS *******************************/
16 /*****************************************************************************/
17
18 SWIFTCALL void indirect_result_1(OUT int *arg0, OUT float *arg1) {}
19 // CHECK-LABEL: define {{.*}} void @indirect_result_1(i32* noalias sret align 4 dereferenceable(4){{.*}}, float* noalias align 4 dereferenceable(4){{.*}})
20
21 // TODO: maybe this shouldn't suppress sret.
22 SWIFTCALL int indirect_result_2(OUT int *arg0, OUT float *arg1) {  __builtin_unreachable(); }
23 // CHECK-LABEL: define {{.*}} i32 @indirect_result_2(i32* noalias align 4 dereferenceable(4){{.*}}, float* noalias align 4 dereferenceable(4){{.*}})
24
25 typedef struct { char array[1024]; } struct_reallybig;
26 SWIFTCALL struct_reallybig indirect_result_3(OUT int *arg0, OUT float *arg1) { __builtin_unreachable(); }
27 // CHECK-LABEL: define {{.*}} void @indirect_result_3({{.*}}* noalias sret {{.*}}, i32* noalias align 4 dereferenceable(4){{.*}}, float* noalias align 4 dereferenceable(4){{.*}})
28
29 SWIFTCALL void context_1(CONTEXT void *self) {}
30 // CHECK-LABEL: define {{.*}} void @context_1(i8* swiftself
31
32 SWIFTCALL void context_2(void *arg0, CONTEXT void *self) {}
33 // CHECK-LABEL: define {{.*}} void @context_2(i8*{{.*}}, i8* swiftself
34
35 SWIFTCALL void context_error_1(CONTEXT int *self, ERROR float **error) {}
36 // CHECK-LABEL: define {{.*}} void @context_error_1(i32* swiftself{{.*}}, float** swifterror)
37 // CHECK:       [[TEMP:%.*]] = alloca float*, align 8
38 // CHECK:       [[T0:%.*]] = load float*, float** [[ERRORARG:%.*]], align 8
39 // CHECK:       store float* [[T0]], float** [[TEMP]], align 8
40 // CHECK:       [[T0:%.*]] = load float*, float** [[TEMP]], align 8
41 // CHECK:       store float* [[T0]], float** [[ERRORARG]], align 8
42 void test_context_error_1() {
43   int x;
44   float *error;
45   context_error_1(&x, &error);
46 }
47 // CHECK-LABEL: define void @test_context_error_1()
48 // CHECK:       [[X:%.*]] = alloca i32, align 4
49 // CHECK:       [[ERROR:%.*]] = alloca float*, align 8
50 // CHECK:       [[TEMP:%.*]] = alloca swifterror float*, align 8
51 // CHECK:       [[T0:%.*]] = load float*, float** [[ERROR]], align 8
52 // CHECK:       store float* [[T0]], float** [[TEMP]], align 8
53 // CHECK:       call [[SWIFTCC:swiftcc]] void @context_error_1(i32* swiftself [[X]], float** swifterror [[TEMP]])
54 // CHECK:       [[T0:%.*]] = load float*, float** [[TEMP]], align 8
55 // CHECK:       store float* [[T0]], float** [[ERROR]], align 8
56
57 SWIFTCALL void context_error_2(short s, CONTEXT int *self, ERROR float **error) {}
58 // CHECK-LABEL: define {{.*}} void @context_error_2(i16{{.*}}, i32* swiftself{{.*}}, float** swifterror)
59
60 /*****************************************************************************/
61 /********************************** LOWERING *********************************/
62 /*****************************************************************************/
63
64 typedef float float3 __attribute__((ext_vector_type(3)));
65 typedef float float4 __attribute__((ext_vector_type(4)));
66 typedef float float8 __attribute__((ext_vector_type(8)));
67 typedef double double2 __attribute__((ext_vector_type(2)));
68 typedef double double4 __attribute__((ext_vector_type(4)));
69 typedef int int3 __attribute__((ext_vector_type(3)));
70 typedef int int4 __attribute__((ext_vector_type(4)));
71 typedef int int5 __attribute__((ext_vector_type(5)));
72 typedef int int8 __attribute__((ext_vector_type(8)));
73 typedef char char16 __attribute__((ext_vector_type(16)));
74 typedef short short8 __attribute__((ext_vector_type(8)));
75 typedef long long long2 __attribute__((ext_vector_type(2)));
76
77 #define TEST(TYPE)                       \
78   SWIFTCALL TYPE return_##TYPE(void) {   \
79     TYPE result = {};                    \
80     return result;                       \
81   }                                      \
82   SWIFTCALL void take_##TYPE(TYPE v) {   \
83   }                                      \
84   void test_##TYPE() {                   \
85     take_##TYPE(return_##TYPE());        \
86   }
87
88 /*****************************************************************************/
89 /*********************************** STRUCTS *********************************/
90 /*****************************************************************************/
91
92 typedef struct {
93 } struct_empty;
94 TEST(struct_empty);
95 // CHECK-LABEL: define {{.*}} @return_struct_empty()
96 // CHECK:   ret void
97 // CHECK-LABEL: define {{.*}} @take_struct_empty()
98 // CHECK:   ret void
99
100 typedef struct {
101   int x;
102   char c0;
103   char c1;
104   float f0;
105   float f1;
106 } struct_1;
107 TEST(struct_1);
108 // CHECK-LABEL: define swiftcc { i64, i64 } @return_struct_1() {{.*}}{
109 // CHECK:   [[RET:%.*]] = alloca [[STRUCT1:%.*]], align 4
110 // CHECK:   [[VAR:%.*]] = alloca [[STRUCT1]], align 4
111 // CHECK:   call void @llvm.memset
112 // CHECK:   call void @llvm.memcpy
113 // CHECK:   [[CAST:%.*]] = bitcast [[STRUCT1]]* %retval to { i64, i64 }*
114 // CHECK:   [[GEP0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
115 // CHECK:   [[T0:%.*]] = load i64, i64* [[GEP0]], align 4
116 // CHECK:   [[GEP1:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
117 // CHECK:   [[T1:%.*]] = load i64, i64* [[GEP1]], align 4
118 // CHECK:   [[R0:%.*]] = insertvalue { i64, i64 } undef, i64 [[T0]], 0
119 // CHECK:   [[R1:%.*]] = insertvalue { i64, i64 } [[R0]], i64 [[T1]], 1
120 // CHECK:   ret { i64, i64 } [[R1]]
121 // CHECK: }
122 // CHECK-LABEL: define swiftcc void @take_struct_1(i64, i64) {{.*}}{
123 // CHECK:   [[V:%.*]] = alloca [[STRUCT1:%.*]], align 4
124 // CHECK:   [[CAST:%.*]] = bitcast [[STRUCT1]]* [[V]] to { i64, i64 }*
125 // CHECK:   [[GEP0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
126 // CHECK:   store i64 %0, i64* [[GEP0]], align 4
127 // CHECK:   [[GEP1:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
128 // CHECK:   store i64 %1, i64* [[GEP1]], align 4
129 // CHECK:   ret void
130 // CHECK: }
131 // CHECK-LABEL: define void @test_struct_1() {{.*}}{
132 // CHECK:   [[AGG:%.*]] = alloca [[STRUCT1:%.*]], align 4
133 // CHECK:   [[RET:%.*]] = call swiftcc { i64, i64 } @return_struct_1()
134 // CHECK:   [[CAST:%.*]] = bitcast [[STRUCT1]]* [[AGG]] to { i64, i64 }*
135 // CHECK:   [[GEP0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
136 // CHECK:   [[E0:%.*]] = extractvalue { i64, i64 } [[RET]], 0
137 // CHECK:   store i64 [[E0]], i64* [[GEP0]], align 4
138 // CHECK:   [[GEP1:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
139 // CHECK:   [[E1:%.*]] = extractvalue { i64, i64 } [[RET]], 1
140 // CHECK:   store i64 [[E1]], i64* [[GEP1]], align 4
141 // CHECK:   [[CAST2:%.*]] = bitcast [[STRUCT1]]* [[AGG]] to { i64, i64 }*
142 // CHECK:   [[GEP2:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST2]], i32 0, i32 0
143 // CHECK:   [[V0:%.*]] = load i64, i64* [[GEP2]], align 4
144 // CHECK:   [[GEP3:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST2]], i32 0, i32 1
145 // CHECK:   [[V1:%.*]] = load i64, i64* [[GEP3]], align 4
146 // CHECK:   call swiftcc void @take_struct_1(i64 [[V0]], i64 [[V1]])
147 // CHECK:   ret void
148 // CHECK: }
149
150 typedef struct {
151   int x;
152   char c0;
153   __attribute__((aligned(2))) char c1;
154   float f0;
155   float f1;
156 } struct_2;
157 TEST(struct_2);
158 // CHECK-LABEL: define swiftcc { i64, i64 } @return_struct_2() {{.*}}{
159 // CHECK:   [[RET:%.*]] = alloca [[STRUCT2_TYPE]], align 4
160 // CHECK:   [[VAR:%.*]] = alloca [[STRUCT2_TYPE]], align 4
161 // CHECK:   [[CASTVAR:%.*]] = bitcast {{.*}} [[VAR]]
162 // CHECK:   call void @llvm.memcpy{{.*}}({{.*}}[[CASTVAR]], {{.*}}[[STRUCT2_RESULT]]
163 // CHECK:   [[CASTRET:%.*]] = bitcast {{.*}} [[RET]]
164 // CHECK:   [[CASTVAR:%.*]] = bitcast {{.*}} [[VAR]]
165 // CHECK:   call void @llvm.memcpy{{.*}}({{.*}}[[CASTRET]], {{.*}}[[CASTVAR]]
166 // CHECK:   [[CAST:%.*]] = bitcast [[STRUCT2_TYPE]]* [[RET]] to { i64, i64 }*
167 // CHECK:   [[GEP0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
168 // CHECK:   [[T0:%.*]] = load i64, i64* [[GEP0]], align 4
169 // CHECK:   [[GEP1:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
170 // CHECK:   [[T1:%.*]] = load i64, i64* [[GEP1]], align 4
171 // CHECK:   [[R0:%.*]] = insertvalue { i64, i64 } undef, i64 [[T0]], 0
172 // CHECK:   [[R1:%.*]] = insertvalue { i64, i64 } [[R0]], i64 [[T1]], 1
173 // CHECK:   ret { i64, i64 } [[R1]]
174 // CHECK: }
175 // CHECK-LABEL: define swiftcc void @take_struct_2(i64, i64) {{.*}}{
176 // CHECK:   [[V:%.*]] = alloca [[STRUCT:%.*]], align 4
177 // CHECK:   [[CAST:%.*]] = bitcast [[STRUCT]]* [[V]] to { i64, i64 }*
178 // CHECK:   [[GEP0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
179 // CHECK:   store i64 %0, i64* [[GEP0]], align 4
180 // CHECK:   [[GEP1:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
181 // CHECK:   store i64 %1, i64* [[GEP1]], align 4
182 // CHECK:   ret void
183 // CHECK: }
184 // CHECK-LABEL: define void @test_struct_2() {{.*}} {
185 // CHECK:   [[TMP:%.*]] = alloca [[STRUCT2_TYPE]], align 4
186 // CHECK:   [[CALL:%.*]] = call swiftcc { i64, i64 } @return_struct_2()
187 // CHECK:   [[CAST_TMP:%.*]] = bitcast [[STRUCT2_TYPE]]* [[TMP]] to { i64, i64 }*
188 // CHECK:   [[GEP:%.*]] = getelementptr inbounds {{.*}} [[CAST_TMP]], i32 0, i32 0
189 // CHECK:   [[T0:%.*]] = extractvalue { i64, i64 } [[CALL]], 0
190 // CHECK:   store i64 [[T0]], i64* [[GEP]], align 4
191 // CHECK:   [[GEP:%.*]] = getelementptr inbounds {{.*}} [[CAST_TMP]], i32 0, i32 1
192 // CHECK:   [[T0:%.*]] = extractvalue { i64, i64 } [[CALL]], 1
193 // CHECK:   store i64 [[T0]], i64* [[GEP]], align 4
194 // CHECK:   [[CAST:%.*]] = bitcast [[STRUCT2_TYPE]]* [[TMP]] to { i64, i64 }*
195 // CHECK:   [[GEP:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
196 // CHECK:   [[R0:%.*]] = load i64, i64* [[GEP]], align 4
197 // CHECK:   [[GEP:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
198 // CHECK:   [[R1:%.*]] = load i64, i64* [[GEP]], align 4
199 // CHECK:   call swiftcc void @take_struct_2(i64 [[R0]], i64 [[R1]])
200 // CHECK:   ret void
201 // CHECK: }
202
203 // There's no way to put a field randomly in the middle of an otherwise
204 // empty storage unit in C, so that case has to be tested in C++, which
205 // can use empty structs to introduce arbitrary padding.  (In C, they end up
206 // with size 0 and so don't affect layout.)
207
208 // Misaligned data rule.
209 typedef struct {
210   char c0;
211   __attribute__((packed)) float f;
212 } struct_misaligned_1;
213 TEST(struct_misaligned_1)
214 // CHECK-LABEL: define swiftcc i64 @return_struct_misaligned_1()
215 // CHECK:  [[RET:%.*]] = alloca [[STRUCT:%.*]], align 1
216 // CHECK:  [[RES:%.*]] = alloca [[STRUCT]], align 1
217 // CHECK:  [[CAST:%.*]] = bitcast [[STRUCT]]* [[RES]] to i8*
218 // CHECK:  call void @llvm.memset{{.*}}(i8* [[CAST]], i8 0, i64 5
219 // CHECK:  [[CASTRET:%.*]] = bitcast [[STRUCT]]* [[RET]] to i8*
220 // CHECK:  [[CASTRES:%.*]] = bitcast [[STRUCT]]* [[RES]] to i8*
221 // CHECK:  call void @llvm.memcpy{{.*}}(i8* [[CASTRET]], i8* [[CASTRES]], i64 5
222 // CHECK:  [[CAST:%.*]] = bitcast [[STRUCT]]* [[RET]] to { i64 }*
223 // CHECK:  [[GEP:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[CAST]], i32 0, i32 0
224 // CHECK:  [[R0:%.*]] = load i64, i64* [[GEP]], align 1
225 // CHECK:  ret i64 [[R0]]
226 // CHECK:}
227 // CHECK-LABEL: define swiftcc void @take_struct_misaligned_1(i64) {{.*}}{
228 // CHECK:   [[V:%.*]] = alloca [[STRUCT:%.*]], align 1
229 // CHECK:   [[CAST:%.*]] = bitcast [[STRUCT]]* [[V]] to { i64 }*
230 // CHECK:   [[GEP:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[CAST]], i32 0, i32 0
231 // CHECK:   store i64 %0, i64* [[GEP]], align 1
232 // CHECK:   ret void
233 // CHECK: }
234 // CHECK: define void @test_struct_misaligned_1() {{.*}}{
235 // CHECK:   [[AGG:%.*]] = alloca [[STRUCT:%.*]], align 1
236 // CHECK:   [[CALL:%.*]] = call swiftcc i64 @return_struct_misaligned_1()
237 // CHECK:   [[T0:%.*]] = bitcast [[STRUCT]]* [[AGG]] to { i64 }*
238 // CHECK:   [[T1:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[T0]], i32 0, i32 0
239 // CHECK:   store i64 [[CALL]], i64* [[T1]], align 1
240 // CHECK:   [[T0:%.*]] = bitcast [[STRUCT]]* [[AGG]] to { i64 }*
241 // CHECK:   [[T1:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[T0]], i32 0, i32 0
242 // CHECK:   [[P:%.*]] = load i64, i64* [[T1]], align 1
243 // CHECK:   call swiftcc void @take_struct_misaligned_1(i64 [[P]])
244 // CHECK:   ret void
245 // CHECK: }
246
247 // Too many scalars.
248 typedef struct {
249   long long x[5];
250 } struct_big_1;
251 TEST(struct_big_1)
252
253 // CHECK-LABEL: define {{.*}} void @return_struct_big_1({{.*}} noalias sret
254
255 // Should not be byval.
256 // CHECK-LABEL: define {{.*}} void @take_struct_big_1({{.*}}*{{( %.*)?}})
257
258 /*****************************************************************************/
259 /********************************* TYPE MERGING ******************************/
260 /*****************************************************************************/
261
262 typedef union {
263   float f;
264   double d;
265 } union_het_fp;
266 TEST(union_het_fp)
267 // CHECK-LABEL: define swiftcc i64 @return_union_het_fp()
268 // CHECK:  [[RET:%.*]] = alloca [[UNION:%.*]], align 8
269 // CHECK:  [[RES:%.*]] = alloca [[UNION]], align 8
270 // CHECK:  [[CAST:%.*]] = bitcast [[UNION]]* [[RES]] to i8*
271 // CHECK:  call void @llvm.memcpy{{.*}}(i8* [[CAST]]
272 // CHECK:  [[CASTRET:%.*]] = bitcast [[UNION]]* [[RET]] to i8*
273 // CHECK:  [[CASTRES:%.*]] = bitcast [[UNION]]* [[RES]] to i8*
274 // CHECK:  call void @llvm.memcpy{{.*}}(i8* [[CASTRET]], i8* [[CASTRES]]
275 // CHECK:  [[CAST:%.*]] = bitcast [[UNION]]* [[RET]] to { i64 }*
276 // CHECK:  [[GEP:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[CAST]], i32 0, i32 0
277 // CHECK:  [[R0:%.*]] = load i64, i64* [[GEP]], align 8
278 // CHECK:  ret i64 [[R0]]
279 // CHECK-LABEL: define swiftcc void @take_union_het_fp(i64) {{.*}}{
280 // CHECK:   [[V:%.*]] = alloca [[UNION:%.*]], align 8
281 // CHECK:   [[CAST:%.*]] = bitcast [[UNION]]* [[V]] to { i64 }*
282 // CHECK:   [[GEP:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[CAST]], i32 0, i32 0
283 // CHECK:   store i64 %0, i64* [[GEP]], align 8
284 // CHECK:   ret void
285 // CHECK: }
286 // CHECK-LABEL: define void @test_union_het_fp() {{.*}}{
287 // CHECK:   [[AGG:%.*]] = alloca [[UNION:%.*]], align 8
288 // CHECK:   [[CALL:%.*]] = call swiftcc i64 @return_union_het_fp()
289 // CHECK:   [[T0:%.*]] = bitcast [[UNION]]* [[AGG]] to { i64 }*
290 // CHECK:   [[T1:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[T0]], i32 0, i32 0
291 // CHECK:   store i64 [[CALL]], i64* [[T1]], align 8
292 // CHECK:   [[T0:%.*]] = bitcast [[UNION]]* [[AGG]] to { i64 }*
293 // CHECK:   [[T1:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[T0]], i32 0, i32 0
294 // CHECK:   [[V0:%.*]] = load i64, i64* [[T1]], align 8
295 // CHECK:   call swiftcc void @take_union_het_fp(i64 [[V0]])
296 // CHECK:   ret void
297 // CHECK: }
298
299
300 typedef union {
301   float f1;
302   float f2;
303 } union_hom_fp;
304 TEST(union_hom_fp)
305 // CHECK-LABEL: define void @test_union_hom_fp()
306 // CHECK:   [[TMP:%.*]] = alloca [[REC:%.*]], align 4
307 // CHECK:   [[CALL:%.*]] = call [[SWIFTCC]] float @return_union_hom_fp()
308 // CHECK:   [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG:{ float }]]*
309 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
310 // CHECK:   store float [[CALL]], float* [[T0]], align 4
311 // CHECK:   [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*
312 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
313 // CHECK:   [[FIRST:%.*]] = load float, float* [[T0]], align 4
314 // CHECK:   call [[SWIFTCC]] void @take_union_hom_fp(float [[FIRST]])
315 // CHECK:   ret void
316
317 typedef union {
318   float f1;
319   float4 fv2;
320 } union_hom_fp_partial;
321 TEST(union_hom_fp_partial)
322 // CHECK: define void @test_union_hom_fp_partial()
323 // CHECK:   [[AGG:%.*]] = alloca [[UNION:%.*]], align 16
324 // CHECK:   [[CALL:%.*]] = call swiftcc { i64, i64 } @return_union_hom_fp_partial()
325 // CHECK:   [[CAST:%.*]] = bitcast [[UNION]]* [[AGG]] to { i64, i64 }*
326 // CHECK:   [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
327 // CHECK:   [[T1:%.*]] = extractvalue { i64, i64 } [[CALL]], 0
328 // CHECK:   store i64 [[T1]], i64* [[T0]], align 16
329 // CHECK:   [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
330 // CHECK:   [[T1:%.*]] = extractvalue { i64, i64 } [[CALL]], 1
331 // CHECK:   store i64 [[T1]], i64* [[T0]], align 8
332 // CHECK:   [[CAST:%.*]] = bitcast [[UNION]]* [[AGG]] to { i64, i64 }*
333 // CHECK:   [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
334 // CHECK:   [[V0:%.*]] = load i64, i64* [[T0]], align 16
335 // CHECK:   [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
336 // CHECK:   [[V1:%.*]] = load i64, i64* [[T0]], align 8
337 // CHECK:   call swiftcc void @take_union_hom_fp_partial(i64 [[V0]], i64 [[V1]])
338 // CHECK:   ret void
339 // CHECK: }
340
341 typedef union {
342   struct { int x, y; } f1;
343   float4 fv2;
344 } union_het_fpv_partial;
345 TEST(union_het_fpv_partial)
346 // CHECK-LABEL: define void @test_union_het_fpv_partial()
347 // CHECK:   [[AGG:%.*]] = alloca [[UNION:%.*]], align 16
348 // CHECK:   [[CALL:%.*]] = call swiftcc { i64, i64 } @return_union_het_fpv_partial()
349 // CHECK:   [[CAST:%.*]] = bitcast [[UNION]]* [[AGG]] to { i64, i64 }*
350 // CHECK:   [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
351 // CHECK:   [[T1:%.*]] = extractvalue { i64, i64 } [[CALL]], 0
352 // CHECK:   store i64 [[T1]], i64* [[T0]], align 16
353 // CHECK:   [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
354 // CHECK:   [[T1:%.*]] = extractvalue { i64, i64 } [[CALL]], 1
355 // CHECK:   store i64 [[T1]], i64* [[T0]], align 8
356 // CHECK:   [[CAST:%.*]] = bitcast [[UNION]]* [[AGG]] to { i64, i64 }*
357 // CHECK:   [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
358 // CHECK:   [[V0:%.*]] = load i64, i64* [[T0]], align 16
359 // CHECK:   [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
360 // CHECK:   [[V1:%.*]] = load i64, i64* [[T0]], align 8
361 // CHECK:   call swiftcc void @take_union_het_fpv_partial(i64 [[V0]], i64 [[V1]])
362 // CHECK:   ret void
363 // CHECK: }
364
365 /*****************************************************************************/
366 /****************************** VECTOR LEGALIZATION **************************/
367 /*****************************************************************************/
368
369 TEST(int4)
370 // CHECK-LABEL: define {{.*}} <4 x i32> @return_int4()
371 // CHECK-LABEL: define {{.*}} @take_int4(<4 x i32>
372
373 TEST(int8)
374 // CHECK-LABEL: define {{.*}} @return_int8()
375 // CHECK:   [[RET:%.*]] = alloca [[REC:<8 x i32>]], align 16
376 // CHECK:   [[VAR:%.*]] = alloca [[REC]], align
377 // CHECK:   store
378 // CHECK:   load
379 // CHECK:   store
380 // CHECK:   [[CAST_TMP:%.*]] = bitcast [[REC]]* [[RET]] to [[AGG:{ <4 x i32>, <4 x i32> }]]*
381 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
382 // CHECK:   [[FIRST:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align
383 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
384 // CHECK:   [[SECOND:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align
385 // CHECK:   [[T0:%.*]] = insertvalue [[UAGG:{ <4 x i32>, <4 x i32> }]] undef, <4 x i32> [[FIRST]], 0
386 // CHECK:   [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], <4 x i32> [[SECOND]], 1
387 // CHECK:   ret [[UAGG]] [[T1]]
388 // CHECK-LABEL: define {{.*}} @take_int8(<4 x i32>, <4 x i32>)
389 // CHECK:   [[V:%.*]] = alloca [[REC]], align
390 // CHECK:   [[CAST_TMP:%.*]] = bitcast [[REC]]* [[V]] to [[AGG]]*
391 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
392 // CHECK:   store <4 x i32> %0, <4 x i32>* [[T0]], align
393 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
394 // CHECK:   store <4 x i32> %1, <4 x i32>* [[T0]], align
395 // CHECK:   ret void
396 // CHECK-LABEL: define void @test_int8()
397 // CHECK:   [[TMP1:%.*]] = alloca [[REC]], align
398 // CHECK:   [[TMP2:%.*]] = alloca [[REC]], align
399 // CHECK:   [[CALL:%.*]] = call [[SWIFTCC]] [[UAGG]] @return_int8()
400 // CHECK:   [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP1]] to [[AGG]]*
401 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
402 // CHECK:   [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0
403 // CHECK:   store <4 x i32> [[T1]], <4 x i32>* [[T0]], align
404 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
405 // CHECK:   [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1
406 // CHECK:   store <4 x i32> [[T1]], <4 x i32>* [[T0]], align
407 // CHECK:   [[V:%.*]] = load [[REC]], [[REC]]* [[TMP1]], align
408 // CHECK:   store [[REC]] [[V]], [[REC]]* [[TMP2]], align
409 // CHECK:   [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP2]] to [[AGG]]*
410 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
411 // CHECK:   [[FIRST:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align
412 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
413 // CHECK:   [[SECOND:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align
414 // CHECK:   call [[SWIFTCC]] void @take_int8(<4 x i32> [[FIRST]], <4 x i32> [[SECOND]])
415 // CHECK:   ret void
416
417 TEST(int5)
418 // CHECK-LABEL: define {{.*}} @return_int5()
419 // CHECK:   [[RET:%.*]] = alloca [[REC:<5 x i32>]], align 16
420 // CHECK:   [[VAR:%.*]] = alloca [[REC]], align
421 // CHECK:   store
422 // CHECK:   load
423 // CHECK:   store
424 // CHECK:   [[CAST_TMP:%.*]] = bitcast [[REC]]* [[RET]] to [[AGG:{ <4 x i32>, i32 }]]*
425 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
426 // CHECK:   [[FIRST:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align
427 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
428 // CHECK:   [[SECOND:%.*]] = load i32, i32* [[T0]], align
429 // CHECK:   [[T0:%.*]] = insertvalue [[UAGG:{ <4 x i32>, i32 }]] undef, <4 x i32> [[FIRST]], 0
430 // CHECK:   [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], i32 [[SECOND]], 1
431 // CHECK:   ret [[UAGG]] [[T1]]
432 // CHECK-LABEL: define {{.*}} @take_int5(<4 x i32>, i32)
433 // CHECK:   [[V:%.*]] = alloca [[REC]], align
434 // CHECK:   [[CAST_TMP:%.*]] = bitcast [[REC]]* [[V]] to [[AGG]]*
435 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
436 // CHECK:   store <4 x i32> %0, <4 x i32>* [[T0]], align
437 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
438 // CHECK:   store i32 %1, i32* [[T0]], align
439 // CHECK:   ret void
440 // CHECK-LABEL: define void @test_int5()
441 // CHECK:   [[TMP1:%.*]] = alloca [[REC]], align
442 // CHECK:   [[TMP2:%.*]] = alloca [[REC]], align
443 // CHECK:   [[CALL:%.*]] = call [[SWIFTCC]] [[UAGG]] @return_int5()
444 // CHECK:   [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP1]] to [[AGG]]*
445 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
446 // CHECK:   [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0
447 // CHECK:   store <4 x i32> [[T1]], <4 x i32>* [[T0]], align
448 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
449 // CHECK:   [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1
450 // CHECK:   store i32 [[T1]], i32* [[T0]], align
451 // CHECK:   [[V:%.*]] = load [[REC]], [[REC]]* [[TMP1]], align
452 // CHECK:   store [[REC]] [[V]], [[REC]]* [[TMP2]], align
453 // CHECK:   [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP2]] to [[AGG]]*
454 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
455 // CHECK:   [[FIRST:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align
456 // CHECK:   [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
457 // CHECK:   [[SECOND:%.*]] = load i32, i32* [[T0]], align
458 // CHECK:   call [[SWIFTCC]] void @take_int5(<4 x i32> [[FIRST]], i32 [[SECOND]])
459 // CHECK:   ret void
460
461 typedef struct {
462   int x;
463   int3 v __attribute__((packed));
464 } misaligned_int3;
465 TEST(misaligned_int3)
466 // CHECK-LABEL: define swiftcc void @take_misaligned_int3(i64, i64)
467
468 typedef struct {
469   float f0;
470 } struct_f1;
471 TEST(struct_f1)
472 // CHECK-LABEL: define swiftcc float @return_struct_f1()
473 // CHECK-LABEL: define swiftcc void @take_struct_f1(float)
474
475 typedef struct {
476   float f0;
477   float f1;
478 } struct_f2;
479 TEST(struct_f2)
480 // CHECK-LABEL: define swiftcc i64 @return_struct_f2()
481 // CHECK-LABEL: define swiftcc void @take_struct_f2(i64)
482
483 typedef struct {
484   float f0;
485   float f1;
486   float f2;
487 } struct_f3;
488 TEST(struct_f3)
489 // CHECK-LABEL: define swiftcc { i64, float } @return_struct_f3()
490 // CHECK-LABEL: define swiftcc void @take_struct_f3(i64, float)
491
492 typedef struct {
493   float f0;
494   float f1;
495   float f2;
496   float f3;
497 } struct_f4;
498 TEST(struct_f4)
499 // CHECK-LABEL: define swiftcc { i64, i64 } @return_struct_f4()
500 // CHECK-LABEL: define swiftcc void @take_struct_f4(i64, i64)
501
502
503 typedef struct {
504   double d0;
505 } struct_d1;
506 TEST(struct_d1)
507 // CHECK-LABEL: define swiftcc double @return_struct_d1()
508 // CHECK-LABEL: define swiftcc void @take_struct_d1(double)
509
510 typedef struct {
511   double d0;
512   double d1;
513 } struct_d2;
514 TEST(struct_d2)
515
516 // CHECK-LABEL: define swiftcc { double, double } @return_struct_d2()
517 // CHECK-LABEL: define swiftcc void @take_struct_d2(double, double)
518 typedef struct {
519   double d0;
520   double d1;
521   double d2;
522 } struct_d3;
523 TEST(struct_d3)
524 // CHECK-LABEL: define swiftcc { double, double, double } @return_struct_d3()
525 // CHECK-LABEL: define swiftcc void @take_struct_d3(double, double, double)
526
527 typedef struct {
528   double d0;
529   double d1;
530   double d2;
531   double d3;
532 } struct_d4;
533 TEST(struct_d4)
534 // CHECK-LABEL: define swiftcc { double, double, double, double } @return_struct_d4()
535 // CHECK-LABEL: define swiftcc void @take_struct_d4(double, double, double, double)
536
537 typedef struct {
538   double d0;
539   double d1;
540   double d2;
541   double d3;
542   double d4;
543 } struct_d5;
544 TEST(struct_d5)
545 // CHECK: define swiftcc void @return_struct_d5([[STRUCT5:%.*]]* noalias sret
546 // CHECK: define swiftcc void @take_struct_d5([[STRUCT5]]
547
548 typedef struct {
549   char c0;
550 } struct_c1;
551 TEST(struct_c1)
552 // CHECK-LABEL: define swiftcc i8 @return_struct_c1()
553 // CHECK-LABEL: define swiftcc void @take_struct_c1(i8)
554
555 typedef struct {
556   char c0;
557   char c1;
558 } struct_c2;
559 TEST(struct_c2)
560 // CHECK-LABEL: define swiftcc i16 @return_struct_c2()
561 // CHECK-LABEL: define swiftcc void @take_struct_c2(i16)
562 //
563
564 typedef struct {
565   char c0;
566   char c1;
567   char c2;
568 } struct_c3;
569 TEST(struct_c3)
570 // CHECK-LABEL: define swiftcc i32 @return_struct_c3()
571 // CHECK-LABEL: define swiftcc void @take_struct_c3(i32)
572
573 typedef struct {
574   char c0;
575   char c1;
576   char c2;
577   char c3;
578 } struct_c4;
579 TEST(struct_c4)
580 // CHECK-LABEL: define swiftcc i32 @return_struct_c4()
581 // CHECK-LABEL: define swiftcc void @take_struct_c4(i32)
582
583 typedef struct {
584   char c0;
585   char c1;
586   char c2;
587   char c3;
588   char c4;
589 } struct_c5;
590 TEST(struct_c5)
591 // CHECK-LABEL: define swiftcc i64 @return_struct_c5()
592 // CHECK-LABEL: define swiftcc void @take_struct_c5(i64)
593 //
594 typedef struct {
595   char c0;
596   char c1;
597   char c2;
598   char c3;
599   char c4;
600   char c5;
601   char c6;
602   char c7;
603   char c8;
604 } struct_c9;
605 TEST(struct_c9)
606 // CHECK-LABEL: define swiftcc { i64, i8 } @return_struct_c9()
607 // CHECK-LABEL: define swiftcc void @take_struct_c9(i64, i8)
608
609 typedef struct {
610   short s0;
611 } struct_s1;
612 TEST(struct_s1)
613 // CHECK-LABEL: define swiftcc i16 @return_struct_s1()
614 // CHECK-LABEL: define swiftcc void @take_struct_s1(i16)
615
616 typedef struct {
617   short s0;
618   short s1;
619 } struct_s2;
620 TEST(struct_s2)
621 // CHECK-LABEL: define swiftcc i32 @return_struct_s2()
622 // CHECK-LABEL: define swiftcc void @take_struct_s2(i32)
623 //
624
625 typedef struct {
626   short s0;
627   short s1;
628   short s2;
629 } struct_s3;
630 TEST(struct_s3)
631 // CHECK-LABEL: define swiftcc i64 @return_struct_s3()
632 // CHECK-LABEL: define swiftcc void @take_struct_s3(i64)
633
634 typedef struct {
635   short s0;
636   short s1;
637   short s2;
638   short s3;
639 } struct_s4;
640 TEST(struct_s4)
641 // CHECK-LABEL: define swiftcc i64 @return_struct_s4()
642 // CHECK-LABEL: define swiftcc void @take_struct_s4(i64)
643
644 typedef struct {
645   short s0;
646   short s1;
647   short s2;
648   short s3;
649   short s4;
650 } struct_s5;
651 TEST(struct_s5)
652 // CHECK-LABEL: define swiftcc { i64, i16 } @return_struct_s5()
653 // CHECK-LABEL: define swiftcc void @take_struct_s5(i64, i16)
654
655
656 typedef struct {
657   int i0;
658 } struct_i1;
659 TEST(struct_i1)
660 // CHECK-LABEL: define swiftcc i32 @return_struct_i1()
661 // CHECK-LABEL: define swiftcc void @take_struct_i1(i32)
662
663 typedef struct {
664   int i0;
665   int i1;
666 } struct_i2;
667 TEST(struct_i2)
668 // CHECK-LABEL: define swiftcc i64 @return_struct_i2()
669 // CHECK-LABEL: define swiftcc void @take_struct_i2(i64)
670
671 typedef struct {
672   int i0;
673   int i1;
674   int i2;
675 } struct_i3;
676 TEST(struct_i3)
677 // CHECK-LABEL: define swiftcc { i64, i32 } @return_struct_i3()
678 // CHECK-LABEL: define swiftcc void @take_struct_i3(i64, i32)
679
680 typedef struct {
681   int i0;
682   int i1;
683   int i2;
684   int i3;
685 } struct_i4;
686 TEST(struct_i4)
687 // CHECK-LABEL: define swiftcc { i64, i64 } @return_struct_i4()
688 // CHECK-LABEL: define swiftcc void @take_struct_i4(i64, i64)
689
690 typedef struct {
691   long long l0;
692 } struct_l1;
693 TEST(struct_l1)
694 // CHECK-LABEL: define swiftcc i64 @return_struct_l1()
695 // CHECK-LABEL: define swiftcc void @take_struct_l1(i64)
696
697 typedef struct {
698   long long l0;
699   long long l1;
700 } struct_l2;
701 TEST(struct_l2)
702 // CHECK-LABEL: define swiftcc { i64, i64 } @return_struct_l2()
703 // CHECK-LABEL: define swiftcc void @take_struct_l2(i64, i64)
704
705 typedef struct {
706   long long l0;
707   long long l1;
708   long long l2;
709 } struct_l3;
710 TEST(struct_l3)
711 // CHECK-LABEL: define swiftcc { i64, i64, i64 } @return_struct_l3()
712 // CHECK-LABEL: define swiftcc void @take_struct_l3(i64, i64, i64)
713
714 typedef struct {
715   long long l0;
716   long long l1;
717   long long l2;
718   long long l3;
719 } struct_l4;
720 TEST(struct_l4)
721 // CHECK-LABEL: define swiftcc { i64, i64, i64, i64 } @return_struct_l4()
722 // CHECK-LABEL: define swiftcc void @take_struct_l4(i64, i64, i64, i64)
723
724 typedef struct {
725   long long l0;
726   long long l1;
727   long long l2;
728   long long l3;
729   long long l4;
730 } struct_l5;
731 TEST(struct_l5)
732 // CHECK: define swiftcc void @return_struct_l5([[STRUCT5:%.*]]* noalias sret
733 // CHECK: define swiftcc void @take_struct_l5([[STRUCT5]]*
734
735 typedef struct {
736   char16 c0;
737 } struct_vc1;
738 TEST(struct_vc1)
739 // CHECK-LABEL: define swiftcc <16 x i8> @return_struct_vc1()
740 // CHECK-LABEL: define swiftcc void @take_struct_vc1(<16 x i8>)
741
742 typedef struct {
743   char16 c0;
744   char16 c1;
745 } struct_vc2;
746 TEST(struct_vc2)
747 // CHECK-LABEL: define swiftcc { <16 x i8>, <16 x i8> } @return_struct_vc2()
748 // CHECK-LABEL: define swiftcc void @take_struct_vc2(<16 x i8>, <16 x i8>)
749
750 typedef struct {
751   char16 c0;
752   char16 c1;
753   char16 c2;
754 } struct_vc3;
755 TEST(struct_vc3)
756 // CHECK-LABEL: define swiftcc { <16 x i8>, <16 x i8>, <16 x i8> } @return_struct_vc3()
757 // CHECK-LABEL: define swiftcc void @take_struct_vc3(<16 x i8>, <16 x i8>, <16 x i8>)
758
759 typedef struct {
760   char16 c0;
761   char16 c1;
762   char16 c2;
763   char16 c3;
764 } struct_vc4;
765 TEST(struct_vc4)
766 // CHECK-LABEL: define swiftcc { <16 x i8>, <16 x i8>, <16 x i8>, <16 x i8> } @return_struct_vc4()
767 // CHECK-LABEL: define swiftcc void @take_struct_vc4(<16 x i8>, <16 x i8>, <16 x i8>, <16 x i8>)
768
769 typedef struct {
770   char16 c0;
771   char16 c1;
772   char16 c2;
773   char16 c3;
774   char16 c4;
775 } struct_vc5;
776 TEST(struct_vc5)
777 // CHECK: define swiftcc void @return_struct_vc5([[STRUCT:%.*]]* noalias sret
778 // CHECK: define swiftcc void @take_struct_vc5([[STRUCT]]
779
780 typedef struct {
781   short8 c0;
782 } struct_vs1;
783 TEST(struct_vs1)
784 // CHECK-LABEL: define swiftcc <8 x i16> @return_struct_vs1()
785 // CHECK-LABEL: define swiftcc void @take_struct_vs1(<8 x i16>)
786
787 typedef struct {
788   short8 c0;
789   short8 c1;
790 } struct_vs2;
791 TEST(struct_vs2)
792 // CHECK-LABEL: define swiftcc { <8 x i16>, <8 x i16> } @return_struct_vs2()
793 // CHECK-LABEL: define swiftcc void @take_struct_vs2(<8 x i16>, <8 x i16>)
794
795 typedef struct {
796   short8 c0;
797   short8 c1;
798   short8 c2;
799 } struct_vs3;
800 TEST(struct_vs3)
801 // CHECK-LABEL: define swiftcc { <8 x i16>, <8 x i16>, <8 x i16> } @return_struct_vs3()
802 // CHECK-LABEL: define swiftcc void @take_struct_vs3(<8 x i16>, <8 x i16>, <8 x i16>)
803
804 typedef struct {
805   short8 c0;
806   short8 c1;
807   short8 c2;
808   short8 c3;
809 } struct_vs4;
810 TEST(struct_vs4)
811 // CHECK-LABEL: define swiftcc { <8 x i16>, <8 x i16>, <8 x i16>, <8 x i16> } @return_struct_vs4()
812 // CHECK-LABEL: define swiftcc void @take_struct_vs4(<8 x i16>, <8 x i16>, <8 x i16>, <8 x i16>)
813
814 typedef struct {
815   short8 c0;
816   short8 c1;
817   short8 c2;
818   short8 c3;
819   short8 c4;
820 } struct_vs5;
821 TEST(struct_vs5)
822 // CHECK: define swiftcc void @return_struct_vs5([[STRUCT:%.*]]* noalias sret
823 // CHECK: define swiftcc void @take_struct_vs5([[STRUCT]]
824
825 typedef struct {
826   int4 c0;
827 } struct_vi1;
828 TEST(struct_vi1)
829 // CHECK-LABEL: define swiftcc <4 x i32> @return_struct_vi1()
830 // CHECK-LABEL: define swiftcc void @take_struct_vi1(<4 x i32>)
831
832 typedef struct {
833   int4 c0;
834   int4 c1;
835 } struct_vi2;
836 TEST(struct_vi2)
837 // CHECK-LABEL: define swiftcc { <4 x i32>, <4 x i32> } @return_struct_vi2()
838 // CHECK-LABEL: define swiftcc void @take_struct_vi2(<4 x i32>, <4 x i32>)
839
840 typedef struct {
841   int4 c0;
842   int4 c1;
843   int4 c2;
844 } struct_vi3;
845 TEST(struct_vi3)
846 // CHECK-LABEL: define swiftcc { <4 x i32>, <4 x i32>, <4 x i32> } @return_struct_vi3()
847 // CHECK-LABEL: define swiftcc void @take_struct_vi3(<4 x i32>, <4 x i32>, <4 x i32>)
848
849 typedef struct {
850   int4 c0;
851   int4 c1;
852   int4 c2;
853   int4 c3;
854 } struct_vi4;
855 TEST(struct_vi4)
856 // CHECK-LABEL: define swiftcc { <4 x i32>, <4 x i32>, <4 x i32>, <4 x i32> } @return_struct_vi4()
857 // CHECK-LABEL: define swiftcc void @take_struct_vi4(<4 x i32>, <4 x i32>, <4 x i32>, <4 x i32>)
858
859 typedef struct {
860   int4 c0;
861   int4 c1;
862   int4 c2;
863   int4 c3;
864   int4 c4;
865 } struct_vi5;
866 TEST(struct_vi5)
867 // CHECK: define swiftcc void @return_struct_vi5([[STRUCT:%.*]]* noalias sret
868 // CHECK: define swiftcc void @take_struct_vi5([[STRUCT]]
869
870 typedef struct {
871   long2 c0;
872 } struct_vl1;
873 TEST(struct_vl1)
874 // CHECK-LABEL: define swiftcc <2 x i64> @return_struct_vl1()
875 // CHECK-LABEL: define swiftcc void @take_struct_vl1(<2 x i64>)
876
877 typedef struct {
878   long2 c0;
879   long2 c1;
880   long2 c2;
881   long2 c3;
882 } struct_vl4;
883 TEST(struct_vl4)
884 // CHECK-LABEL: define swiftcc { <2 x i64>, <2 x i64>, <2 x i64>, <2 x i64> } @return_struct_vl4()
885 // CHECK-LABEL: define swiftcc void @take_struct_vl4(<2 x i64>, <2 x i64>, <2 x i64>, <2 x i64>)
886
887 typedef struct {
888   long2 c0;
889   long2 c1;
890   long2 c2;
891   long2 c3;
892   long2 c4;
893 } struct_vl5;
894 TEST(struct_vl5)
895 // CHECK: define swiftcc void @return_struct_vl5([[STRUCT:%.*]]* noalias sret
896 // CHECK: define swiftcc void @take_struct_vl5([[STRUCT]]
897
898 typedef struct {
899   double2 c0;
900 } struct_vd1;
901 TEST(struct_vd1)
902 // CHECK-LABEL: define swiftcc <2 x double> @return_struct_vd1()
903 // CHECK-LABEL: define swiftcc void @take_struct_vd1(<2 x double>)
904
905 typedef struct {
906   double2 c0;
907   double2 c1;
908   double2 c2;
909   double2 c3;
910 } struct_vd4;
911 TEST(struct_vd4)
912 // CHECK-LABEL: define swiftcc { <2 x double>, <2 x double>, <2 x double>, <2 x double> } @return_struct_vd4()
913 // CHECK-LABEL: define swiftcc void @take_struct_vd4(<2 x double>, <2 x double>, <2 x double>, <2 x double>)
914
915 typedef struct {
916   double2 c0;
917   double2 c1;
918   double2 c2;
919   double2 c3;
920   double2 c4;
921 } struct_vd5;
922 TEST(struct_vd5)
923 // CHECK: define swiftcc void @return_struct_vd5([[STRUCT:%.*]]* noalias sret
924 // CHECK: define swiftcc void @take_struct_vd5([[STRUCT]]
925
926 typedef struct {
927   double4 c0;
928 } struct_vd41;
929 TEST(struct_vd41)
930 // CHECK-LABEL: define swiftcc { <2 x double>, <2 x double> } @return_struct_vd41()
931 // CHECK-LABEL: define swiftcc void @take_struct_vd41(<2 x double>, <2 x double>)
932
933 typedef struct {
934   double4 c0;
935   double4 c1;
936 } struct_vd42;
937 TEST(struct_vd42)
938 // CHECK-LABEL: define swiftcc { <2 x double>, <2 x double>, <2 x double>, <2 x double> } @return_struct_vd42()
939 // CHECK-LABEL: define swiftcc void @take_struct_vd42(<2 x double>, <2 x double>, <2 x double>, <2 x double>)
940
941 typedef struct {
942   double4 c0;
943   double4 c1;
944   double4 c2;
945 } struct_vd43;
946 TEST(struct_vd43)
947 // CHECK: define swiftcc void @return_struct_vd43([[STRUCT:%.*]]* noalias sret
948 // CHECK: define swiftcc void @take_struct_vd43([[STRUCT]]
949
950 typedef struct {
951   float4 c0;
952 } struct_vf1;
953 TEST(struct_vf1)
954 // CHECK-LABEL: define swiftcc <4 x float> @return_struct_vf1()
955 // CHECK-LABEL: define swiftcc void @take_struct_vf1(<4 x float>)
956
957 typedef struct {
958   float4 c0;
959   float4 c1;
960 } struct_vf2;
961 TEST(struct_vf2)
962 // CHECK-LABEL: define swiftcc { <4 x float>, <4 x float> } @return_struct_vf2()
963 // CHECK-LABEL: define swiftcc void @take_struct_vf2(<4 x float>, <4 x float>)
964
965 typedef struct {
966   float4 c0;
967   float4 c1;
968   float4 c2;
969   float4 c3;
970 } struct_vf4;
971 TEST(struct_vf4)
972 // CHECK-LABEL: define swiftcc { <4 x float>, <4 x float>, <4 x float>, <4 x float> } @return_struct_vf4()
973 // CHECK-LABEL: define swiftcc void @take_struct_vf4(<4 x float>, <4 x float>, <4 x float>, <4 x float>)
974
975 typedef struct {
976   float4 c0;
977   float4 c1;
978   float4 c2;
979   float4 c3;
980   float4 c4;
981 } struct_vf5;
982 TEST(struct_vf5)
983 // CHECK: define swiftcc void @return_struct_vf5([[STRUCT:%.*]]* noalias sret
984 // CHECK: define swiftcc void @take_struct_vf5([[STRUCT]]
985
986 typedef struct {
987   float8 c0;
988 } struct_vf81;
989 TEST(struct_vf81)
990 // CHECK-LABEL: define swiftcc { <4 x float>, <4 x float> } @return_struct_vf81()
991 // CHECK-LABEL: define swiftcc void @take_struct_vf81(<4 x float>, <4 x float>)
992
993 // Don't crash.
994 typedef union {
995 int4 v[2];
996 struct {
997   int LSW;
998   int d7;
999   int d6;
1000   int d5;
1001   int d4;
1002   int d3;
1003   int d2;
1004   int MSW;
1005 } s;
1006 } union_het_vecint;
1007 TEST(union_het_vecint)
1008 // CHECK: define swiftcc void @return_union_het_vecint([[UNION:%.*]]* noalias sret
1009 // CHECK: define swiftcc void @take_union_het_vecint([[UNION]]*
1010
1011 typedef struct {
1012   float3 f3;
1013 } struct_v1f3;
1014 TEST(struct_v1f3)
1015 // ARM64-LABEL: define swiftcc { <2 x float>, float } @return_struct_v1f3()
1016 // ARM64-LABEL: define swiftcc void @take_struct_v1f3(<2 x float>, float)