blob: f5e63fe4d8dff5ed5d5eabeabf665704f0b12370 [file] [log] [blame]
Arnold Schwaighofer2d556f22016-10-13 17:17:36 +00001// 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
4#define SWIFTCALL __attribute__((swiftcall))
5#define OUT __attribute__((swift_indirect_result))
6#define ERROR __attribute__((swift_error_result))
7#define CONTEXT __attribute__((swift_context))
8
9// CHECK: [[STRUCT2_RESULT:@.*]] = private {{.*}} constant [[STRUCT2_TYPE:%.*]] { i32 0, i8 0, i8 undef, i8 0, float 0.000000e+00, float 0.000000e+00 }
10
11/*****************************************************************************/
12/****************************** PARAMETER ABIS *******************************/
13/*****************************************************************************/
14
15SWIFTCALL void indirect_result_1(OUT int *arg0, OUT float *arg1) {}
16// CHECK-LABEL: define {{.*}} void @indirect_result_1(i32* noalias sret align 4 dereferenceable(4){{.*}}, float* noalias align 4 dereferenceable(4){{.*}})
17
18// TODO: maybe this shouldn't suppress sret.
19SWIFTCALL int indirect_result_2(OUT int *arg0, OUT float *arg1) { __builtin_unreachable(); }
20// CHECK-LABEL: define {{.*}} i32 @indirect_result_2(i32* noalias align 4 dereferenceable(4){{.*}}, float* noalias align 4 dereferenceable(4){{.*}})
21
22typedef struct { char array[1024]; } struct_reallybig;
23SWIFTCALL struct_reallybig indirect_result_3(OUT int *arg0, OUT float *arg1) { __builtin_unreachable(); }
24// CHECK-LABEL: define {{.*}} void @indirect_result_3({{.*}}* noalias sret {{.*}}, i32* noalias align 4 dereferenceable(4){{.*}}, float* noalias align 4 dereferenceable(4){{.*}})
25
26SWIFTCALL void context_1(CONTEXT void *self) {}
27// CHECK-LABEL: define {{.*}} void @context_1(i8* swiftself
28
29SWIFTCALL void context_2(void *arg0, CONTEXT void *self) {}
30// CHECK-LABEL: define {{.*}} void @context_2(i8*{{.*}}, i8* swiftself
31
32SWIFTCALL void context_error_1(CONTEXT int *self, ERROR float **error) {}
33// CHECK-LABEL: define {{.*}} void @context_error_1(i32* swiftself{{.*}}, float** swifterror)
34// CHECK: [[TEMP:%.*]] = alloca float*, align 8
35// CHECK: [[T0:%.*]] = load float*, float** [[ERRORARG:%.*]], align 8
36// CHECK: store float* [[T0]], float** [[TEMP]], align 8
37// CHECK: [[T0:%.*]] = load float*, float** [[TEMP]], align 8
38// CHECK: store float* [[T0]], float** [[ERRORARG]], align 8
39void test_context_error_1() {
40 int x;
41 float *error;
42 context_error_1(&x, &error);
43}
44// CHECK-LABEL: define void @test_context_error_1()
45// CHECK: [[X:%.*]] = alloca i32, align 4
46// CHECK: [[ERROR:%.*]] = alloca float*, align 8
47// CHECK: [[TEMP:%.*]] = alloca swifterror float*, align 8
48// CHECK: [[T0:%.*]] = load float*, float** [[ERROR]], align 8
49// CHECK: store float* [[T0]], float** [[TEMP]], align 8
50// CHECK: call [[SWIFTCC:swiftcc]] void @context_error_1(i32* swiftself [[X]], float** swifterror [[TEMP]])
51// CHECK: [[T0:%.*]] = load float*, float** [[TEMP]], align 8
52// CHECK: store float* [[T0]], float** [[ERROR]], align 8
53
54SWIFTCALL void context_error_2(short s, CONTEXT int *self, ERROR float **error) {}
55// CHECK-LABEL: define {{.*}} void @context_error_2(i16{{.*}}, i32* swiftself{{.*}}, float** swifterror)
56
57/*****************************************************************************/
58/********************************** LOWERING *********************************/
59/*****************************************************************************/
60
61typedef float float4 __attribute__((ext_vector_type(4)));
62typedef float float8 __attribute__((ext_vector_type(8)));
63typedef double double2 __attribute__((ext_vector_type(2)));
64typedef double double4 __attribute__((ext_vector_type(4)));
65typedef int int3 __attribute__((ext_vector_type(3)));
66typedef int int4 __attribute__((ext_vector_type(4)));
67typedef int int5 __attribute__((ext_vector_type(5)));
68typedef int int8 __attribute__((ext_vector_type(8)));
69
70#define TEST(TYPE) \
71 SWIFTCALL TYPE return_##TYPE(void) { \
72 TYPE result = {}; \
73 return result; \
74 } \
75 SWIFTCALL void take_##TYPE(TYPE v) { \
76 } \
77 void test_##TYPE() { \
78 take_##TYPE(return_##TYPE()); \
79 }
80
81/*****************************************************************************/
82/*********************************** STRUCTS *********************************/
83/*****************************************************************************/
84
85typedef struct {
86} struct_empty;
87TEST(struct_empty);
88// CHECK-LABEL: define {{.*}} @return_struct_empty()
89// CHECK: ret void
90// CHECK-LABEL: define {{.*}} @take_struct_empty()
91// CHECK: ret void
92
93typedef struct {
94 int x;
95 char c0;
96 char c1;
97 float f0;
98 float f1;
99} struct_1;
100TEST(struct_1);
101// CHECK-LABEL: define swiftcc { i64, i64 } @return_struct_1() {{.*}}{
102// CHECK: [[RET:%.*]] = alloca [[STRUCT1:%.*]], align 4
103// CHECK: [[VAR:%.*]] = alloca [[STRUCT1]], align 4
104// CHECK: call void @llvm.memset
105// CHECK: call void @llvm.memcpy
106// CHECK: [[CAST:%.*]] = bitcast [[STRUCT1]]* %retval to { i64, i64 }*
107// CHECK: [[GEP0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
108// CHECK: [[T0:%.*]] = load i64, i64* [[GEP0]], align 4
109// CHECK: [[GEP1:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
110// CHECK: [[T1:%.*]] = load i64, i64* [[GEP1]], align 4
111// CHECK: [[R0:%.*]] = insertvalue { i64, i64 } undef, i64 [[T0]], 0
112// CHECK: [[R1:%.*]] = insertvalue { i64, i64 } [[R0]], i64 [[T1]], 1
113// CHECK: ret { i64, i64 } [[R1]]
114// CHECK: }
115// CHECK-LABEL: define swiftcc void @take_struct_1(i64, i64) {{.*}}{
116// CHECK: [[V:%.*]] = alloca [[STRUCT1:%.*]], align 4
117// CHECK: [[CAST:%.*]] = bitcast [[STRUCT1]]* [[V]] to { i64, i64 }*
118// CHECK: [[GEP0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
119// CHECK: store i64 %0, i64* [[GEP0]], align 4
120// CHECK: [[GEP1:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
121// CHECK: store i64 %1, i64* [[GEP1]], align 4
122// CHECK: ret void
123// CHECK: }
124// CHECK-LABEL: define void @test_struct_1() {{.*}}{
125// CHECK: [[AGG:%.*]] = alloca [[STRUCT1:%.*]], align 4
126// CHECK: [[RET:%.*]] = call swiftcc { i64, i64 } @return_struct_1()
127// CHECK: [[CAST:%.*]] = bitcast [[STRUCT1]]* [[AGG]] to { i64, i64 }*
128// CHECK: [[GEP0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
129// CHECK: [[E0:%.*]] = extractvalue { i64, i64 } [[RET]], 0
130// CHECK: store i64 [[E0]], i64* [[GEP0]], align 4
131// CHECK: [[GEP1:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
132// CHECK: [[E1:%.*]] = extractvalue { i64, i64 } [[RET]], 1
133// CHECK: store i64 [[E1]], i64* [[GEP1]], align 4
134// CHECK: [[CAST2:%.*]] = bitcast [[STRUCT1]]* [[AGG]] to { i64, i64 }*
135// CHECK: [[GEP2:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST2]], i32 0, i32 0
136// CHECK: [[V0:%.*]] = load i64, i64* [[GEP2]], align 4
137// CHECK: [[GEP3:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST2]], i32 0, i32 1
138// CHECK: [[V1:%.*]] = load i64, i64* [[GEP3]], align 4
139// CHECK: call swiftcc void @take_struct_1(i64 [[V0]], i64 [[V1]])
140// CHECK: ret void
141// CHECK: }
142
143typedef struct {
144 int x;
145 char c0;
146 __attribute__((aligned(2))) char c1;
147 float f0;
148 float f1;
149} struct_2;
150TEST(struct_2);
151// CHECK-LABEL: define swiftcc { i64, i64 } @return_struct_2() {{.*}}{
152// CHECK: [[RET:%.*]] = alloca [[STRUCT2_TYPE]], align 4
153// CHECK: [[VAR:%.*]] = alloca [[STRUCT2_TYPE]], align 4
154// CHECK: [[CASTVAR:%.*]] = bitcast {{.*}} [[VAR]]
155// CHECK: call void @llvm.memcpy{{.*}}({{.*}}[[CASTVAR]], {{.*}}[[STRUCT2_RESULT]]
156// CHECK: [[CASTRET:%.*]] = bitcast {{.*}} [[RET]]
157// CHECK: [[CASTVAR:%.*]] = bitcast {{.*}} [[VAR]]
158// CHECK: call void @llvm.memcpy{{.*}}({{.*}}[[CASTRET]], {{.*}}[[CASTVAR]]
159// CHECK: [[CAST:%.*]] = bitcast [[STRUCT2_TYPE]]* [[RET]] to { i64, i64 }*
160// CHECK: [[GEP0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
161// CHECK: [[T0:%.*]] = load i64, i64* [[GEP0]], align 4
162// CHECK: [[GEP1:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
163// CHECK: [[T1:%.*]] = load i64, i64* [[GEP1]], align 4
164// CHECK: [[R0:%.*]] = insertvalue { i64, i64 } undef, i64 [[T0]], 0
165// CHECK: [[R1:%.*]] = insertvalue { i64, i64 } [[R0]], i64 [[T1]], 1
166// CHECK: ret { i64, i64 } [[R1]]
167// CHECK: }
168// CHECK-LABEL: define swiftcc void @take_struct_2(i64, i64) {{.*}}{
169// CHECK: [[V:%.*]] = alloca [[STRUCT:%.*]], align 4
170// CHECK: [[CAST:%.*]] = bitcast [[STRUCT]]* [[V]] to { i64, i64 }*
171// CHECK: [[GEP0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
172// CHECK: store i64 %0, i64* [[GEP0]], align 4
173// CHECK: [[GEP1:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
174// CHECK: store i64 %1, i64* [[GEP1]], align 4
175// CHECK: ret void
176// CHECK: }
177// CHECK-LABEL: define void @test_struct_2() {{.*}} {
178// CHECK: [[TMP:%.*]] = alloca [[STRUCT2_TYPE]], align 4
179// CHECK: [[CALL:%.*]] = call swiftcc { i64, i64 } @return_struct_2()
180// CHECK: [[CAST_TMP:%.*]] = bitcast [[STRUCT2_TYPE]]* [[TMP]] to { i64, i64 }*
181// CHECK: [[GEP:%.*]] = getelementptr inbounds {{.*}} [[CAST_TMP]], i32 0, i32 0
182// CHECK: [[T0:%.*]] = extractvalue { i64, i64 } [[CALL]], 0
183// CHECK: store i64 [[T0]], i64* [[GEP]], align 4
184// CHECK: [[GEP:%.*]] = getelementptr inbounds {{.*}} [[CAST_TMP]], i32 0, i32 1
185// CHECK: [[T0:%.*]] = extractvalue { i64, i64 } [[CALL]], 1
186// CHECK: store i64 [[T0]], i64* [[GEP]], align 4
187// CHECK: [[CAST:%.*]] = bitcast [[STRUCT2_TYPE]]* [[TMP]] to { i64, i64 }*
188// CHECK: [[GEP:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
189// CHECK: [[R0:%.*]] = load i64, i64* [[GEP]], align 4
190// CHECK: [[GEP:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
191// CHECK: [[R1:%.*]] = load i64, i64* [[GEP]], align 4
192// CHECK: call swiftcc void @take_struct_2(i64 [[R0]], i64 [[R1]])
193// CHECK: ret void
194// CHECK: }
195
196// There's no way to put a field randomly in the middle of an otherwise
197// empty storage unit in C, so that case has to be tested in C++, which
198// can use empty structs to introduce arbitrary padding. (In C, they end up
199// with size 0 and so don't affect layout.)
200
201// Misaligned data rule.
202typedef struct {
203 char c0;
204 __attribute__((packed)) float f;
205} struct_misaligned_1;
206TEST(struct_misaligned_1)
207// CHECK-LABEL: define swiftcc i64 @return_struct_misaligned_1()
208// CHECK: [[RET:%.*]] = alloca [[STRUCT:%.*]], align 1
209// CHECK: [[RES:%.*]] = alloca [[STRUCT]], align 1
210// CHECK: [[CAST:%.*]] = bitcast [[STRUCT]]* [[RES]] to i8*
211// CHECK: call void @llvm.memset{{.*}}(i8* [[CAST]], i8 0, i64 5
212// CHECK: [[CASTRET:%.*]] = bitcast [[STRUCT]]* [[RET]] to i8*
213// CHECK: [[CASTRES:%.*]] = bitcast [[STRUCT]]* [[RES]] to i8*
214// CHECK: call void @llvm.memcpy{{.*}}(i8* [[CASTRET]], i8* [[CASTRES]], i64 5
215// CHECK: [[CAST:%.*]] = bitcast [[STRUCT]]* [[RET]] to { i64 }*
216// CHECK: [[GEP:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[CAST]], i32 0, i32 0
217// CHECK: [[R0:%.*]] = load i64, i64* [[GEP]], align 1
218// CHECK: ret i64 [[R0]]
219// CHECK:}
220// CHECK-LABEL: define swiftcc void @take_struct_misaligned_1(i64) {{.*}}{
221// CHECK: [[V:%.*]] = alloca [[STRUCT:%.*]], align 1
222// CHECK: [[CAST:%.*]] = bitcast [[STRUCT]]* [[V]] to { i64 }*
223// CHECK: [[GEP:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[CAST]], i32 0, i32 0
224// CHECK: store i64 %0, i64* [[GEP]], align 1
225// CHECK: ret void
226// CHECK: }
227// CHECK: define void @test_struct_misaligned_1() {{.*}}{
228// CHECK: [[AGG:%.*]] = alloca [[STRUCT:%.*]], align 1
229// CHECK: [[CALL:%.*]] = call swiftcc i64 @return_struct_misaligned_1()
230// CHECK: [[T0:%.*]] = bitcast [[STRUCT]]* [[AGG]] to { i64 }*
231// CHECK: [[T1:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[T0]], i32 0, i32 0
232// CHECK: store i64 [[CALL]], i64* [[T1]], align 1
233// CHECK: [[T0:%.*]] = bitcast [[STRUCT]]* [[AGG]] to { i64 }*
234// CHECK: [[T1:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[T0]], i32 0, i32 0
235// CHECK: [[P:%.*]] = load i64, i64* [[T1]], align 1
236// CHECK: call swiftcc void @take_struct_misaligned_1(i64 [[P]])
237// CHECK: ret void
238// CHECK: }
239
240// Too many scalars.
241typedef struct {
242 long long x[5];
243} struct_big_1;
244TEST(struct_big_1)
245
246// CHECK-LABEL: define {{.*}} void @return_struct_big_1({{.*}} noalias sret
247
248// Should not be byval.
249// CHECK-LABEL: define {{.*}} void @take_struct_big_1({{.*}}*{{( %.*)?}})
250
251/*****************************************************************************/
252/********************************* TYPE MERGING ******************************/
253/*****************************************************************************/
254
255typedef union {
256 float f;
257 double d;
258} union_het_fp;
259TEST(union_het_fp)
260// CHECK-LABEL: define swiftcc i64 @return_union_het_fp()
261// CHECK: [[RET:%.*]] = alloca [[UNION:%.*]], align 8
262// CHECK: [[RES:%.*]] = alloca [[UNION]], align 8
263// CHECK: [[CAST:%.*]] = bitcast [[UNION]]* [[RES]] to i8*
264// CHECK: call void @llvm.memcpy{{.*}}(i8* [[CAST]]
265// CHECK: [[CASTRET:%.*]] = bitcast [[UNION]]* [[RET]] to i8*
266// CHECK: [[CASTRES:%.*]] = bitcast [[UNION]]* [[RES]] to i8*
267// CHECK: call void @llvm.memcpy{{.*}}(i8* [[CASTRET]], i8* [[CASTRES]]
268// CHECK: [[CAST:%.*]] = bitcast [[UNION]]* [[RET]] to { i64 }*
269// CHECK: [[GEP:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[CAST]], i32 0, i32 0
270// CHECK: [[R0:%.*]] = load i64, i64* [[GEP]], align 8
271// CHECK: ret i64 [[R0]]
272// CHECK-LABEL: define swiftcc void @take_union_het_fp(i64) {{.*}}{
273// CHECK: [[V:%.*]] = alloca [[UNION:%.*]], align 8
274// CHECK: [[CAST:%.*]] = bitcast [[UNION]]* [[V]] to { i64 }*
275// CHECK: [[GEP:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[CAST]], i32 0, i32 0
276// CHECK: store i64 %0, i64* [[GEP]], align 8
277// CHECK: ret void
278// CHECK: }
279// CHECK-LABEL: define void @test_union_het_fp() {{.*}}{
280// CHECK: [[AGG:%.*]] = alloca [[UNION:%.*]], align 8
281// CHECK: [[CALL:%.*]] = call swiftcc i64 @return_union_het_fp()
282// CHECK: [[T0:%.*]] = bitcast [[UNION]]* [[AGG]] to { i64 }*
283// CHECK: [[T1:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[T0]], i32 0, i32 0
284// CHECK: store i64 [[CALL]], i64* [[T1]], align 8
285// CHECK: [[T0:%.*]] = bitcast [[UNION]]* [[AGG]] to { i64 }*
286// CHECK: [[T1:%.*]] = getelementptr inbounds { i64 }, { i64 }* [[T0]], i32 0, i32 0
287// CHECK: [[V0:%.*]] = load i64, i64* [[T1]], align 8
288// CHECK: call swiftcc void @take_union_het_fp(i64 [[V0]])
289// CHECK: ret void
290// CHECK: }
291
292
293typedef union {
294 float f1;
295 float f2;
296} union_hom_fp;
297TEST(union_hom_fp)
298// CHECK-LABEL: define void @test_union_hom_fp()
299// CHECK: [[TMP:%.*]] = alloca [[REC:%.*]], align 4
300// CHECK: [[CALL:%.*]] = call [[SWIFTCC]] float @return_union_hom_fp()
301// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG:{ float }]]*
302// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
303// CHECK: store float [[CALL]], float* [[T0]], align 4
304// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*
305// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
306// CHECK: [[FIRST:%.*]] = load float, float* [[T0]], align 4
307// CHECK: call [[SWIFTCC]] void @take_union_hom_fp(float [[FIRST]])
308// CHECK: ret void
309
310typedef union {
311 float f1;
312 float4 fv2;
313} union_hom_fp_partial;
314TEST(union_hom_fp_partial)
315// CHECK: define void @test_union_hom_fp_partial()
316// CHECK: [[AGG:%.*]] = alloca [[UNION:%.*]], align 16
317// CHECK: [[CALL:%.*]] = call swiftcc { i64, i64 } @return_union_hom_fp_partial()
318// CHECK: [[CAST:%.*]] = bitcast [[UNION]]* [[AGG]] to { i64, i64 }*
319// CHECK: [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
320// CHECK: [[T1:%.*]] = extractvalue { i64, i64 } [[CALL]], 0
321// CHECK: store i64 [[T1]], i64* [[T0]], align 16
322// CHECK: [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
323// CHECK: [[T1:%.*]] = extractvalue { i64, i64 } [[CALL]], 1
324// CHECK: store i64 [[T1]], i64* [[T0]], align 8
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: [[V0:%.*]] = load i64, i64* [[T0]], align 16
328// CHECK: [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
329// CHECK: [[V1:%.*]] = load i64, i64* [[T0]], align 8
330// CHECK: call swiftcc void @take_union_hom_fp_partial(i64 [[V0]], i64 [[V1]])
331// CHECK: ret void
332// CHECK: }
333
334typedef union {
335 struct { int x, y; } f1;
336 float4 fv2;
337} union_het_fpv_partial;
338TEST(union_het_fpv_partial)
339// CHECK-LABEL: define void @test_union_het_fpv_partial()
340// CHECK: [[AGG:%.*]] = alloca [[UNION:%.*]], align 16
341// CHECK: [[CALL:%.*]] = call swiftcc { i64, i64 } @return_union_het_fpv_partial()
342// CHECK: [[CAST:%.*]] = bitcast [[UNION]]* [[AGG]] to { i64, i64 }*
343// CHECK: [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 0
344// CHECK: [[T1:%.*]] = extractvalue { i64, i64 } [[CALL]], 0
345// CHECK: store i64 [[T1]], i64* [[T0]], align 16
346// CHECK: [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
347// CHECK: [[T1:%.*]] = extractvalue { i64, i64 } [[CALL]], 1
348// CHECK: store i64 [[T1]], i64* [[T0]], align 8
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: [[V0:%.*]] = load i64, i64* [[T0]], align 16
352// CHECK: [[T0:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[CAST]], i32 0, i32 1
353// CHECK: [[V1:%.*]] = load i64, i64* [[T0]], align 8
354// CHECK: call swiftcc void @take_union_het_fpv_partial(i64 [[V0]], i64 [[V1]])
355// CHECK: ret void
356// CHECK: }
357
358/*****************************************************************************/
359/****************************** VECTOR LEGALIZATION **************************/
360/*****************************************************************************/
361
362TEST(int4)
363// CHECK-LABEL: define {{.*}} <4 x i32> @return_int4()
364// CHECK-LABEL: define {{.*}} @take_int4(<4 x i32>
365
366TEST(int8)
367// CHECK-LABEL: define {{.*}} @return_int8()
368// CHECK: [[RET:%.*]] = alloca [[REC:<8 x i32>]], align 16
369// CHECK: [[VAR:%.*]] = alloca [[REC]], align
370// CHECK: store
371// CHECK: load
372// CHECK: store
373// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[RET]] to [[AGG:{ <4 x i32>, <4 x i32> }]]*
374// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
375// CHECK: [[FIRST:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align
376// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
377// CHECK: [[SECOND:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align
378// CHECK: [[T0:%.*]] = insertvalue [[UAGG:{ <4 x i32>, <4 x i32> }]] undef, <4 x i32> [[FIRST]], 0
379// CHECK: [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], <4 x i32> [[SECOND]], 1
380// CHECK: ret [[UAGG]] [[T1]]
381// CHECK-LABEL: define {{.*}} @take_int8(<4 x i32>, <4 x i32>)
382// CHECK: [[V:%.*]] = alloca [[REC]], align
383// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[V]] to [[AGG]]*
384// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
385// CHECK: store <4 x i32> %0, <4 x i32>* [[T0]], align
386// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
387// CHECK: store <4 x i32> %1, <4 x i32>* [[T0]], align
388// CHECK: ret void
389// CHECK-LABEL: define void @test_int8()
390// CHECK: [[TMP1:%.*]] = alloca [[REC]], align
391// CHECK: [[TMP2:%.*]] = alloca [[REC]], align
392// CHECK: [[CALL:%.*]] = call [[SWIFTCC]] [[UAGG]] @return_int8()
393// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP1]] to [[AGG]]*
394// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
395// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0
396// CHECK: store <4 x i32> [[T1]], <4 x i32>* [[T0]], align
397// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
398// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1
399// CHECK: store <4 x i32> [[T1]], <4 x i32>* [[T0]], align
400// CHECK: [[V:%.*]] = load [[REC]], [[REC]]* [[TMP1]], align
401// CHECK: store [[REC]] [[V]], [[REC]]* [[TMP2]], align
402// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP2]] to [[AGG]]*
403// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
404// CHECK: [[FIRST:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align
405// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
406// CHECK: [[SECOND:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align
407// CHECK: call [[SWIFTCC]] void @take_int8(<4 x i32> [[FIRST]], <4 x i32> [[SECOND]])
408// CHECK: ret void
409
410TEST(int5)
411// CHECK-LABEL: define {{.*}} @return_int5()
412// CHECK: [[RET:%.*]] = alloca [[REC:<5 x i32>]], align 16
413// CHECK: [[VAR:%.*]] = alloca [[REC]], align
414// CHECK: store
415// CHECK: load
416// CHECK: store
417// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[RET]] to [[AGG:{ <4 x i32>, i32 }]]*
418// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
419// CHECK: [[FIRST:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align
420// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
421// CHECK: [[SECOND:%.*]] = load i32, i32* [[T0]], align
422// CHECK: [[T0:%.*]] = insertvalue [[UAGG:{ <4 x i32>, i32 }]] undef, <4 x i32> [[FIRST]], 0
423// CHECK: [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], i32 [[SECOND]], 1
424// CHECK: ret [[UAGG]] [[T1]]
425// CHECK-LABEL: define {{.*}} @take_int5(<4 x i32>, i32)
426// CHECK: [[V:%.*]] = alloca [[REC]], align
427// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[V]] to [[AGG]]*
428// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
429// CHECK: store <4 x i32> %0, <4 x i32>* [[T0]], align
430// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
431// CHECK: store i32 %1, i32* [[T0]], align
432// CHECK: ret void
433// CHECK-LABEL: define void @test_int5()
434// CHECK: [[TMP1:%.*]] = alloca [[REC]], align
435// CHECK: [[TMP2:%.*]] = alloca [[REC]], align
436// CHECK: [[CALL:%.*]] = call [[SWIFTCC]] [[UAGG]] @return_int5()
437// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP1]] to [[AGG]]*
438// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
439// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0
440// CHECK: store <4 x i32> [[T1]], <4 x i32>* [[T0]], align
441// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
442// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1
443// CHECK: store i32 [[T1]], i32* [[T0]], align
444// CHECK: [[V:%.*]] = load [[REC]], [[REC]]* [[TMP1]], align
445// CHECK: store [[REC]] [[V]], [[REC]]* [[TMP2]], align
446// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP2]] to [[AGG]]*
447// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
448// CHECK: [[FIRST:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align
449// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1
450// CHECK: [[SECOND:%.*]] = load i32, i32* [[T0]], align
451// CHECK: call [[SWIFTCC]] void @take_int5(<4 x i32> [[FIRST]], i32 [[SECOND]])
452// CHECK: ret void
453
454typedef struct {
455 int x;
456 int3 v __attribute__((packed));
457} misaligned_int3;
458TEST(misaligned_int3)
459// CHECK-LABEL: define swiftcc void @take_misaligned_int3(i64, i64)
460
461typedef struct {
462 float f0;
463} struct_f1;
464TEST(struct_f1)
465// CHECK-LABEL: define swiftcc float @return_struct_f1()
466// CHECK-LABEL: define swiftcc void @take_struct_f1(float)
467
468typedef struct {
469 float f0;
470 float f1;
471} struct_f2;
472TEST(struct_f2)
473// CHECK-LABEL: define swiftcc i64 @return_struct_f2()
474// CHECK-LABEL: define swiftcc void @take_struct_f2(i64)
475
476typedef struct {
477 float f0;
478 float f1;
479 float f2;
480} struct_f3;
481TEST(struct_f3)
482// CHECK-LABEL: define swiftcc { i64, float } @return_struct_f3()
483// CHECK-LABEL: define swiftcc void @take_struct_f3(i64, float)
484
485typedef struct {
486 float f0;
487 float f1;
488 float f2;
489 float f3;
490} struct_f4;
491TEST(struct_f4)
492// CHECK-LABEL: define swiftcc { i64, i64 } @return_struct_f4()
493// CHECK-LABEL: define swiftcc void @take_struct_f4(i64, i64)
494
495
496typedef struct {
497 double d0;
498} struct_d1;
499TEST(struct_d1)
500// CHECK-LABEL: define swiftcc double @return_struct_d1()
501// CHECK-LABEL: define swiftcc void @take_struct_d1(double)
502
503typedef struct {
504 double d0;
505 double d1;
506} struct_d2;
507TEST(struct_d2)
508// CHECK-LABEL: define swiftcc { double, double } @return_struct_d2()
509// CHECK-LABEL: define swiftcc void @take_struct_d2(double, double)
510
511typedef struct {
512 char c0;
513} struct_c1;
514TEST(struct_c1)
515// CHECK-LABEL: define swiftcc i8 @return_struct_c1()
516// CHECK-LABEL: define swiftcc void @take_struct_c1(i8)
517
518typedef struct {
519 char c0;
520 char c1;
521} struct_c2;
522TEST(struct_c2)
523// CHECK-LABEL: define swiftcc i16 @return_struct_c2()
524// CHECK-LABEL: define swiftcc void @take_struct_c2(i16)
525//
526
527typedef struct {
528 char c0;
529 char c1;
530 char c2;
531} struct_c3;
532TEST(struct_c3)
533// CHECK-LABEL: define swiftcc i32 @return_struct_c3()
534// CHECK-LABEL: define swiftcc void @take_struct_c3(i32)
535
536typedef struct {
537 char c0;
538 char c1;
539 char c2;
540 char c3;
541} struct_c4;
542TEST(struct_c4)
543// CHECK-LABEL: define swiftcc i32 @return_struct_c4()
544// CHECK-LABEL: define swiftcc void @take_struct_c4(i32)
545
546typedef struct {
547 char c0;
548 char c1;
549 char c2;
550 char c3;
551 char c4;
552} struct_c5;
553TEST(struct_c5)
554// CHECK-LABEL: define swiftcc i64 @return_struct_c5()
555// CHECK-LABEL: define swiftcc void @take_struct_c5(i64)
556//
557typedef struct {
558 char c0;
559 char c1;
560 char c2;
561 char c3;
562 char c4;
563 char c5;
564 char c6;
565 char c7;
566 char c8;
567} struct_c9;
568TEST(struct_c9)
569// CHECK-LABEL: define swiftcc { i64, i8 } @return_struct_c9()
570// CHECK-LABEL: define swiftcc void @take_struct_c9(i64, i8)
571
572typedef struct {
573 short s0;
574} struct_s1;
575TEST(struct_s1)
576// CHECK-LABEL: define swiftcc i16 @return_struct_s1()
577// CHECK-LABEL: define swiftcc void @take_struct_s1(i16)
578
579typedef struct {
580 short s0;
581 short s1;
582} struct_s2;
583TEST(struct_s2)
584// CHECK-LABEL: define swiftcc i32 @return_struct_s2()
585// CHECK-LABEL: define swiftcc void @take_struct_s2(i32)
586//
587
588typedef struct {
589 short s0;
590 short s1;
591 short s2;
592} struct_s3;
593TEST(struct_s3)
594// CHECK-LABEL: define swiftcc i64 @return_struct_s3()
595// CHECK-LABEL: define swiftcc void @take_struct_s3(i64)
596
597typedef struct {
598 short s0;
599 short s1;
600 short s2;
601 short s3;
602} struct_s4;
603TEST(struct_s4)
604// CHECK-LABEL: define swiftcc i64 @return_struct_s4()
605// CHECK-LABEL: define swiftcc void @take_struct_s4(i64)
606
607typedef struct {
608 short s0;
609 short s1;
610 short s2;
611 short s3;
612 short s4;
613} struct_s5;
614TEST(struct_s5)
615// CHECK-LABEL: define swiftcc { i64, i16 } @return_struct_s5()
616// CHECK-LABEL: define swiftcc void @take_struct_s5(i64, i16)
617
618
619typedef struct {
620 int i0;
621} struct_i1;
622TEST(struct_i1)
623// CHECK-LABEL: define swiftcc i32 @return_struct_i1()
624// CHECK-LABEL: define swiftcc void @take_struct_i1(i32)
625
626typedef struct {
627 int i0;
628 int i1;
629} struct_i2;
630TEST(struct_i2)
631// CHECK-LABEL: define swiftcc i64 @return_struct_i2()
632// CHECK-LABEL: define swiftcc void @take_struct_i2(i64)
633
634typedef struct {
635 int i0;
636 int i1;
637 int i2;
638} struct_i3;
639TEST(struct_i3)
640// CHECK-LABEL: define swiftcc { i64, i32 } @return_struct_i3()
641// CHECK-LABEL: define swiftcc void @take_struct_i3(i64, i32)
642
643typedef struct {
644 int i0;
645 int i1;
646 int i2;
647 int i3;
648} struct_i4;
649TEST(struct_i4)
650// CHECK-LABEL: define swiftcc { i64, i64 } @return_struct_i4()
651// CHECK-LABEL: define swiftcc void @take_struct_i4(i64, i64)
652
653typedef struct {
654 long long l0;
655} struct_l1;
656TEST(struct_l1)
657// CHECK-LABEL: define swiftcc i64 @return_struct_l1()
658// CHECK-LABEL: define swiftcc void @take_struct_l1(i64)
659
660typedef struct {
661 long long l0;
662 long long l1;
663} struct_l2;
664TEST(struct_l2)
665// CHECK-LABEL: define swiftcc { i64, i64 } @return_struct_l2()
666// CHECK-LABEL: define swiftcc void @take_struct_l2(i64, i64)
667
668typedef struct {
669 long long l0;
670 long long l1;
671 long long l2;
672} struct_l3;
673TEST(struct_l3)
674// CHECK-LABEL: define swiftcc { i64, i64, i64 } @return_struct_l3()
675// CHECK-LABEL: define swiftcc void @take_struct_l3(i64, i64, i64)
676
677typedef struct {
678 long long l0;
679 long long l1;
680 long long l2;
681 long long l3;
682} struct_l4;
683TEST(struct_l4)
684// CHECK-LABEL: define swiftcc { i64, i64, i64, i64 } @return_struct_l4()
685// CHECK-LABEL: define swiftcc void @take_struct_l4(i64, i64, i64, i64)
686
687typedef struct {
688 long long l0;
689 long long l1;
690 long long l2;
691 long long l3;
692 long long l4;
693} struct_l5;
694TEST(struct_l5)
695// CHECK: define swiftcc void @return_struct_l5([[STRUCT5:%.*]]* noalias sret
696// CHECK: define swiftcc void @take_struct_l5([[STRUCT5]]*