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