1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s| FileCheck %s
2 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -target-feature +avx | FileCheck %s -check-prefix=AVX
5 // CHECK-LABEL: define signext i8 @f0()
10 // CHECK-LABEL: define signext i16 @f1()
15 // CHECK-LABEL: define i32 @f2()
20 // CHECK-LABEL: define float @f3()
25 // CHECK-LABEL: define double @f4()
30 // CHECK-LABEL: define x86_fp80 @f5()
31 long double f5(void) {
35 // CHECK-LABEL: define void @f6(i8 signext %a0, i16 signext %a1, i32 %a2, i64 %a3, i8* %a4)
36 void f6(char a0, short a1, int a2, long long a3, void *a4) {
39 // CHECK-LABEL: define void @f7(i32 %a0)
40 typedef enum { A, B, C } e7;
44 // Test merging/passing of upper eightbyte with X87 class.
46 // CHECK-LABEL: define void @f8_1(%union.u8* noalias sret %agg.result)
47 // CHECK-LABEL: define void @f8_2(%union.u8* byval align 16 %a0)
52 union u8 f8_1() { while (1) {} }
53 void f8_2(union u8 a0) {}
55 // CHECK-LABEL: define i64 @f9()
56 struct s9 { int a; int b; int : 0; } f9(void) { while (1) {} }
58 // CHECK-LABEL: define void @f10(i64 %a0.coerce)
59 struct s10 { int a; int b; int : 0; };
60 void f10(struct s10 a0) {}
62 // CHECK-LABEL: define void @f11(%union.anon* noalias sret %agg.result)
63 union { long double a; float b; } f11() { while (1) {} }
65 // CHECK-LABEL: define i32 @f12_0()
66 // CHECK-LABEL: define void @f12_1(i32 %a0.coerce)
67 struct s12 { int a __attribute__((aligned(16))); };
68 struct s12 f12_0(void) { while (1) {} }
69 void f12_1(struct s12 a0) {}
71 // Check that sret parameter is accounted for when checking available integer
73 // CHECK: define void @f13(%struct.s13_0* noalias sret %agg.result, i32 %a, i32 %b, i32 %c, i32 %d, {{.*}}* byval align 8 %e, i32 %f)
75 struct s13_0 { long long f0[3]; };
76 struct s13_1 { long long f0[2]; };
77 struct s13_0 f13(int a, int b, int c, int d,
78 struct s13_1 e, int f) { while (1) {} }
80 // CHECK: define void @f14({{.*}}, i8 signext %X)
81 void f14(int a, int b, int c, int d, int e, int f, char X) {}
83 // CHECK: define void @f15({{.*}}, i8* %X)
84 void f15(int a, int b, int c, int d, int e, int f, void *X) {}
86 // CHECK: define void @f16({{.*}}, float %X)
87 void f16(float a, float b, float c, float d, float e, float f, float g, float h,
90 // CHECK: define void @f17({{.*}}, x86_fp80 %X)
91 void f17(float a, float b, float c, float d, float e, float f, float g, float h,
94 // Check for valid coercion. The struct should be passed/returned as i32, not
95 // as i64 for better code quality.
97 // CHECK-LABEL: define void @f18(i32 %a, i32 %f18_arg1.coerce)
98 struct f18_s0 { int f0; };
99 void f18(int a, struct f18_s0 f18_arg1) { while (1) {} }
101 // Check byval alignment.
103 // CHECK-LABEL: define void @f19(%struct.s19* byval align 16 %x)
107 void f19(struct s19 x) {}
109 // CHECK-LABEL: define void @f20(%struct.s20* byval align 32 %x)
110 struct __attribute__((aligned(32))) s20 {
114 void f20(struct s20 x) {}
122 // CHECK-LABEL: define i8* @f21(i64 %S.coerce0, i8* %S.coerce1)
123 const char *f21(struct StringRef S) { return S.x+S.Ptr; }
126 typedef __attribute__ ((aligned(16))) struct f22s { unsigned long long x[2]; } L;
127 void f22(L x, L y) { }
129 // CHECK: %x = alloca{{.*}}, align 16
130 // CHECK: %y = alloca{{.*}}, align 16
142 void f23(int A, struct f23S B) {
143 // CHECK-LABEL: define void @f23(i32 %A, i64 %B.coerce0, i32 %B.coerce1)
146 struct f24s { long a; int b; };
148 struct f23S f24(struct f23S *X, struct f24s *P2) {
151 // CHECK: define { i64, i32 } @f24(%struct.f23S* %X, %struct.f24s* %P2)
155 typedef float v4f32 __attribute__((__vector_size__(16)));
157 // CHECK-LABEL: define <4 x float> @f25(<4 x float> %X)
159 // CHECK: alloca <4 x float>
161 // CHECK: store <4 x float> %X, <4 x float>*
163 // CHECK: ret <4 x float>
172 struct foo26 f26(struct foo26 *P) {
173 // CHECK: define { i32*, float* } @f26(%struct.foo26* %P)
178 struct v4f32wrapper {
182 struct v4f32wrapper f27(struct v4f32wrapper X) {
183 // CHECK-LABEL: define <4 x float> @f27(<4 x float> %X.coerce)
192 void f28(struct f28c C) {
193 // CHECK-LABEL: define void @f28(double %C.coerce0, i32 %C.coerce1)
203 void f29a(struct f29a A) {
204 // CHECK-LABEL: define void @f29a(double %A.coerce0, i32 %A.coerce1)
208 struct S0 { char f0[8]; char f2; char f3; char f4; };
209 void f30(struct S0 p_4) {
210 // CHECK-LABEL: define void @f30(i64 %p_4.coerce0, i24 %p_4.coerce1)
213 // Pass the third element as a float when followed by tail padding.
215 struct f31foo { float a, b, c; };
216 float f31(struct f31foo X) {
217 // CHECK-LABEL: define float @f31(<2 x float> %X.coerce0, float %X.coerce1)
221 _Complex float f32(_Complex float A, _Complex float B) {
223 // CHECK-LABEL: define <2 x float> @f32(<2 x float> %A.coerce, <2 x float> %B.coerce)
229 struct f33s { long x; float c,d; };
231 void f33(va_list X) {
232 va_arg(X, struct f33s);
235 typedef unsigned long long v1i64 __attribute__((__vector_size__(8)));
238 // CHECK-LABEL: define i64 @f34(i64 %arg.coerce)
239 v1i64 f34(v1i64 arg) { return arg; }
243 // CHECK-LABEL: define i64 @f35(i64 %arg.coerce)
244 typedef unsigned long v1i64_2 __attribute__((__vector_size__(8)));
245 v1i64_2 f35(v1i64_2 arg) { return arg+arg; }
248 // CHECK: declare void @func(%struct._str* byval align 16)
249 typedef struct _str {
263 // CHECK-LABEL: define double @f36(double %arg.coerce)
264 typedef unsigned v2i32 __attribute((__vector_size__(8)));
265 v2i32 f36(v2i32 arg) { return arg; }
267 // AVX: declare void @f38(<8 x float>)
268 // AVX: declare void @f37(<8 x float>)
269 // CHECK: declare void @f38(%struct.s256* byval align 32)
270 // CHECK: declare void @f37(<8 x float>* byval align 32)
271 typedef float __m256 __attribute__ ((__vector_size__ (32)));
281 void f39() { f38(x38); f37(x37); }
283 // The two next tests make sure that the struct below is passed
284 // in the same way regardless of avx being used
286 // CHECK: declare void @func40(%struct.t128* byval align 16)
287 typedef float __m128 __attribute__ ((__vector_size__ (16)));
288 typedef struct t128 {
293 extern void func40(two128 s);
294 void func41(two128 s) {
298 // CHECK: declare void @func42(%struct.t128_2* byval align 16)
302 typedef struct t128_2 {
306 extern void func42(SA s);
311 // CHECK-LABEL: define i32 @f44
313 // CHECK-NEXT: and {{.*}}, -32
314 // CHECK-NEXT: inttoptr
315 typedef int T44 __attribute((vector_size(32)));
316 struct s44 { T44 x; int y; };
317 int f44(int i, ...) {
318 __builtin_va_list ap;
319 __builtin_va_start(ap, i);
320 struct s44 s = __builtin_va_arg(ap, struct s44);
321 __builtin_va_end(ap);
325 // Text that vec3 returns the correct LLVM IR type.
326 // AVX-LABEL: define i32 @foo(<3 x i64> %X)
327 typedef long long3 __attribute((ext_vector_type(3)));
333 // Make sure we don't use a varargs convention for a function without a
334 // prototype where AVX types are involved.
336 // AVX: call i32 bitcast (i32 (...)* @f45 to i32 (<8 x float>)*)
339 void test45() { f45(x45); }
341 // Make sure we use byval to pass 64-bit vectors in memory; the LLVM call
342 // lowering can't handle this case correctly because it runs after legalization.
344 // CHECK: call void @f46({{.*}}<2 x float>* byval align 8 {{.*}}, <2 x float>* byval align 8 {{.*}})
345 typedef float v46 __attribute((vector_size(8)));
346 void f46(v46,v46,v46,v46,v46,v46,v46,v46,v46,v46);
347 void test46() { v46 x = {1,2}; f46(x,x,x,x,x,x,x,x,x,x); }
349 // Check that we pass the struct below without using byval, which helps out
353 // CHECK: call void @f47(i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}})
354 struct s47 { unsigned a; };
355 void f47(int,int,int,int,int,int,struct s47);
356 void test47(int a, struct s47 b) { f47(a, a, a, a, a, a, b); }
359 // In the following example, there are holes in T4 at the 3rd byte and the 4th
360 // byte, however, T2 does not have those holes. T4 is chosen to be the
361 // representing type for union T1, but we can't use load or store of T4 since
362 // it will skip the 3rd byte and the 4th byte.
363 // In general, Since we don't accurately represent the data fields of a union,
364 // do not use load or store of the representing llvm type for the union.
365 typedef _Complex int T2;
366 typedef _Complex char T5;
367 typedef _Complex int T7;
368 typedef struct T4 { T5 field0; T7 field1; } T4;
369 typedef union T1 { T2 field0; T4 field1; } T1;
378 void test49_helper(double, ...);
379 void test49(double d, double e) {
382 // CHECK-LABEL: define void @test49(
383 // CHECK: [[T0:%.*]] = load double*
384 // CHECK-NEXT: [[T1:%.*]] = load double*
385 // CHECK-NEXT: call void (double, ...)* @test49_helper(double [[T0]], double [[T1]])
387 void test50_helper();
388 void test50(double d, double e) {
391 // CHECK-LABEL: define void @test50(
392 // CHECK: [[T0:%.*]] = load double*
393 // CHECK-NEXT: [[T1:%.*]] = load double*
394 // CHECK-NEXT: call void (double, double, ...)* bitcast (void (...)* @test50_helper to void (double, double, ...)*)(double [[T0]], double [[T1]])
396 struct test51_s { __uint128_t intval; };
397 void test51(struct test51_s *s, __builtin_va_list argList) {
398 *s = __builtin_va_arg(argList, struct test51_s);
401 // CHECK-LABEL: define void @test51
402 // CHECK: [[TMP_ADDR:%.*]] = alloca [[STRUCT_TEST51:%.*]], align 16
404 // CHECK: [[REG_SAVE_AREA_PTR:%.*]] = getelementptr inbounds {{.*}}, i32 0, i32 3
405 // CHECK-NEXT: [[REG_SAVE_AREA:%.*]] = load i8** [[REG_SAVE_AREA_PTR]]
406 // CHECK-NEXT: [[VALUE_ADDR:%.*]] = getelementptr i8* [[REG_SAVE_AREA]], i32 {{.*}}
407 // CHECK-NEXT: [[CASTED_VALUE_ADDR:%.*]] = bitcast i8* [[VALUE_ADDR]] to [[STRUCT_TEST51]]
408 // CHECK-NEXT: [[CASTED_TMP_ADDR:%.*]] = bitcast [[STRUCT_TEST51]]* [[TMP_ADDR]] to i8*
409 // CHECK-NEXT: [[RECASTED_VALUE_ADDR:%.*]] = bitcast [[STRUCT_TEST51]]* [[CASTED_VALUE_ADDR]] to i8*
410 // CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[CASTED_TMP_ADDR]], i8* [[RECASTED_VALUE_ADDR]], i64 16, i32 8, i1 false)
411 // CHECK-NEXT: add i32 {{.*}}, 16
412 // CHECK-NEXT: store i32 {{.*}}, i32* {{.*}}
413 // CHECK-NEXT: br label
415 void test52_helper(int, ...);
418 test52_helper(0, x52, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0i);
420 // AVX: @test52_helper(i32 0, <8 x float> {{%[a-zA-Z0-9]+}}, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double {{%[a-zA-Z0-9]+}}, double {{%[a-zA-Z0-9]+}})
422 void test53(__m256 *m, __builtin_va_list argList) {
423 *m = __builtin_va_arg(argList, __m256);
425 // AVX-LABEL: define void @test53
429 void test54_helper(__m256, ...);
432 test54_helper(x54, x54, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0i);
433 test54_helper(x54, x54, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0i);
435 // AVX: @test54_helper(<8 x float> {{%[a-zA-Z0-9]+}}, <8 x float> {{%[a-zA-Z0-9]+}}, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double {{%[a-zA-Z0-9]+}}, double {{%[a-zA-Z0-9]+}})
436 // AVX: @test54_helper(<8 x float> {{%[a-zA-Z0-9]+}}, <8 x float> {{%[a-zA-Z0-9]+}}, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, { double, double }* byval align 8 {{%[a-zA-Z0-9]+}})