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
5 // REQUIRES: aarch64-registered-target,x86-registered-target
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))
12 // CHECK: [[STRUCT2_RESULT:@.*]] = private {{.*}} constant [[STRUCT2_TYPE:%.*]] { i32 0, i8 0, i8 undef, i8 0, float 0.000000e+00, float 0.000000e+00 }
14 /*****************************************************************************/
15 /****************************** PARAMETER ABIS *******************************/
16 /*****************************************************************************/
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){{.*}})
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){{.*}})
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){{.*}})
29 SWIFTCALL void context_1(CONTEXT void *self) {}
30 // CHECK-LABEL: define {{.*}} void @context_1(i8* swiftself
32 SWIFTCALL void context_2(void *arg0, CONTEXT void *self) {}
33 // CHECK-LABEL: define {{.*}} void @context_2(i8*{{.*}}, i8* swiftself
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() {
45 context_error_1(&x, &error);
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
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)
60 /*****************************************************************************/
61 /********************************** LOWERING *********************************/
62 /*****************************************************************************/
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)));
78 SWIFTCALL TYPE return_##TYPE(void) { \
82 SWIFTCALL void take_##TYPE(TYPE v) { \
84 void test_##TYPE() { \
85 take_##TYPE(return_##TYPE()); \
88 /*****************************************************************************/
89 /*********************************** STRUCTS *********************************/
90 /*****************************************************************************/
95 // CHECK-LABEL: define {{.*}} @return_struct_empty()
97 // CHECK-LABEL: define {{.*}} @take_struct_empty()
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]]
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
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]])
153 __attribute__((aligned(2))) char c1;
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]]
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
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]])
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.)
208 // Misaligned data rule.
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]]
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
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]])
253 // CHECK-LABEL: define {{.*}} void @return_struct_big_1({{.*}} noalias sret
255 // Should not be byval.
256 // CHECK-LABEL: define {{.*}} void @take_struct_big_1({{.*}}*{{( %.*)?}})
258 /*****************************************************************************/
259 /********************************* TYPE MERGING ******************************/
260 /*****************************************************************************/
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
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]])
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]])
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]])
342 struct { int x, y; } f1;
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]])
365 /*****************************************************************************/
366 /****************************** VECTOR LEGALIZATION **************************/
367 /*****************************************************************************/
370 // CHECK-LABEL: define {{.*}} <4 x i32> @return_int4()
371 // CHECK-LABEL: define {{.*}} @take_int4(<4 x i32>
374 // CHECK-LABEL: define {{.*}} @return_int8()
375 // CHECK: [[RET:%.*]] = alloca [[REC:<8 x i32>]], align 16
376 // CHECK: [[VAR:%.*]] = alloca [[REC]], align
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
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]])
418 // CHECK-LABEL: define {{.*}} @return_int5()
419 // CHECK: [[RET:%.*]] = alloca [[REC:<5 x i32>]], align 16
420 // CHECK: [[VAR:%.*]] = alloca [[REC]], align
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
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]])
463 int3 v __attribute__((packed));
465 TEST(misaligned_int3)
466 // CHECK-LABEL: define swiftcc void @take_misaligned_int3(i64, i64)
472 // CHECK-LABEL: define swiftcc float @return_struct_f1()
473 // CHECK-LABEL: define swiftcc void @take_struct_f1(float)
480 // CHECK-LABEL: define swiftcc i64 @return_struct_f2()
481 // CHECK-LABEL: define swiftcc void @take_struct_f2(i64)
489 // CHECK-LABEL: define swiftcc { i64, float } @return_struct_f3()
490 // CHECK-LABEL: define swiftcc void @take_struct_f3(i64, float)
499 // CHECK-LABEL: define swiftcc { i64, i64 } @return_struct_f4()
500 // CHECK-LABEL: define swiftcc void @take_struct_f4(i64, i64)
507 // CHECK-LABEL: define swiftcc double @return_struct_d1()
508 // CHECK-LABEL: define swiftcc void @take_struct_d1(double)
516 // CHECK-LABEL: define swiftcc { double, double } @return_struct_d2()
517 // CHECK-LABEL: define swiftcc void @take_struct_d2(double, double)
524 // CHECK-LABEL: define swiftcc { double, double, double } @return_struct_d3()
525 // CHECK-LABEL: define swiftcc void @take_struct_d3(double, double, double)
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)
545 // CHECK: define swiftcc void @return_struct_d5([[STRUCT5:%.*]]* noalias sret
546 // CHECK: define swiftcc void @take_struct_d5([[STRUCT5]]
552 // CHECK-LABEL: define swiftcc i8 @return_struct_c1()
553 // CHECK-LABEL: define swiftcc void @take_struct_c1(i8)
560 // CHECK-LABEL: define swiftcc i16 @return_struct_c2()
561 // CHECK-LABEL: define swiftcc void @take_struct_c2(i16)
570 // CHECK-LABEL: define swiftcc i32 @return_struct_c3()
571 // CHECK-LABEL: define swiftcc void @take_struct_c3(i32)
580 // CHECK-LABEL: define swiftcc i32 @return_struct_c4()
581 // CHECK-LABEL: define swiftcc void @take_struct_c4(i32)
591 // CHECK-LABEL: define swiftcc i64 @return_struct_c5()
592 // CHECK-LABEL: define swiftcc void @take_struct_c5(i64)
606 // CHECK-LABEL: define swiftcc { i64, i8 } @return_struct_c9()
607 // CHECK-LABEL: define swiftcc void @take_struct_c9(i64, i8)
613 // CHECK-LABEL: define swiftcc i16 @return_struct_s1()
614 // CHECK-LABEL: define swiftcc void @take_struct_s1(i16)
621 // CHECK-LABEL: define swiftcc i32 @return_struct_s2()
622 // CHECK-LABEL: define swiftcc void @take_struct_s2(i32)
631 // CHECK-LABEL: define swiftcc i64 @return_struct_s3()
632 // CHECK-LABEL: define swiftcc void @take_struct_s3(i64)
641 // CHECK-LABEL: define swiftcc i64 @return_struct_s4()
642 // CHECK-LABEL: define swiftcc void @take_struct_s4(i64)
652 // CHECK-LABEL: define swiftcc { i64, i16 } @return_struct_s5()
653 // CHECK-LABEL: define swiftcc void @take_struct_s5(i64, i16)
660 // CHECK-LABEL: define swiftcc i32 @return_struct_i1()
661 // CHECK-LABEL: define swiftcc void @take_struct_i1(i32)
668 // CHECK-LABEL: define swiftcc i64 @return_struct_i2()
669 // CHECK-LABEL: define swiftcc void @take_struct_i2(i64)
677 // CHECK-LABEL: define swiftcc { i64, i32 } @return_struct_i3()
678 // CHECK-LABEL: define swiftcc void @take_struct_i3(i64, i32)
687 // CHECK-LABEL: define swiftcc { i64, i64 } @return_struct_i4()
688 // CHECK-LABEL: define swiftcc void @take_struct_i4(i64, i64)
694 // CHECK-LABEL: define swiftcc i64 @return_struct_l1()
695 // CHECK-LABEL: define swiftcc void @take_struct_l1(i64)
702 // CHECK-LABEL: define swiftcc { i64, i64 } @return_struct_l2()
703 // CHECK-LABEL: define swiftcc void @take_struct_l2(i64, i64)
711 // CHECK-LABEL: define swiftcc { i64, i64, i64 } @return_struct_l3()
712 // CHECK-LABEL: define swiftcc void @take_struct_l3(i64, i64, i64)
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)
732 // CHECK: define swiftcc void @return_struct_l5([[STRUCT5:%.*]]* noalias sret
733 // CHECK: define swiftcc void @take_struct_l5([[STRUCT5]]*
739 // CHECK-LABEL: define swiftcc <16 x i8> @return_struct_vc1()
740 // CHECK-LABEL: define swiftcc void @take_struct_vc1(<16 x i8>)
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>)
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>)
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>)
777 // CHECK: define swiftcc void @return_struct_vc5([[STRUCT:%.*]]* noalias sret
778 // CHECK: define swiftcc void @take_struct_vc5([[STRUCT]]
784 // CHECK-LABEL: define swiftcc <8 x i16> @return_struct_vs1()
785 // CHECK-LABEL: define swiftcc void @take_struct_vs1(<8 x i16>)
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>)
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>)
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>)
822 // CHECK: define swiftcc void @return_struct_vs5([[STRUCT:%.*]]* noalias sret
823 // CHECK: define swiftcc void @take_struct_vs5([[STRUCT]]
829 // CHECK-LABEL: define swiftcc <4 x i32> @return_struct_vi1()
830 // CHECK-LABEL: define swiftcc void @take_struct_vi1(<4 x i32>)
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>)
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>)
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>)
867 // CHECK: define swiftcc void @return_struct_vi5([[STRUCT:%.*]]* noalias sret
868 // CHECK: define swiftcc void @take_struct_vi5([[STRUCT]]
874 // CHECK-LABEL: define swiftcc <2 x i64> @return_struct_vl1()
875 // CHECK-LABEL: define swiftcc void @take_struct_vl1(<2 x i64>)
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>)
895 // CHECK: define swiftcc void @return_struct_vl5([[STRUCT:%.*]]* noalias sret
896 // CHECK: define swiftcc void @take_struct_vl5([[STRUCT]]
902 // CHECK-LABEL: define swiftcc <2 x double> @return_struct_vd1()
903 // CHECK-LABEL: define swiftcc void @take_struct_vd1(<2 x double>)
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>)
923 // CHECK: define swiftcc void @return_struct_vd5([[STRUCT:%.*]]* noalias sret
924 // CHECK: define swiftcc void @take_struct_vd5([[STRUCT]]
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>)
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>)
947 // CHECK: define swiftcc void @return_struct_vd43([[STRUCT:%.*]]* noalias sret
948 // CHECK: define swiftcc void @take_struct_vd43([[STRUCT]]
954 // CHECK-LABEL: define swiftcc <4 x float> @return_struct_vf1()
955 // CHECK-LABEL: define swiftcc void @take_struct_vf1(<4 x float>)
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>)
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>)
983 // CHECK: define swiftcc void @return_struct_vf5([[STRUCT:%.*]]* noalias sret
984 // CHECK: define swiftcc void @take_struct_vf5([[STRUCT]]
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>)
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]]*
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)