xref: /llvm-project/clang/test/CodeGen/sysv_abi.c (revision 39db5e1ed87363a9ffea81e53520b542201b3262)
1 // RUN: %clang_cc1 -triple x86_64-pc-win32 -emit-llvm  -target-cpu skylake-avx512 < %s | FileCheck %s --check-prefixes=CHECK,AVX
2 // RUN: %clang_cc1 -triple x86_64-linux -emit-llvm  -target-cpu skylake-avx512 < %s | FileCheck %s --check-prefixes=CHECK,AVX
3 // RUN: %clang_cc1 -triple x86_64-pc-win32 -emit-llvm < %s | FileCheck %s --check-prefixes=CHECK,NOAVX
4 // RUN: %clang_cc1 -triple x86_64-linux -emit-llvm < %s | FileCheck %s --check-prefixes=CHECK,NOAVX
5 
6 #define SYSV_CC __attribute__((sysv_abi))
7 
8 // Make sure we coerce structs according to the SysV rules instead of passing
9 // them indirectly as we would for Win64.
10 struct StringRef {
11   char *Str;
12   __SIZE_TYPE__ Size;
13 };
14 extern volatile char gc;
15 void SYSV_CC take_stringref(struct StringRef s);
callit(void)16 void callit(void) {
17   struct StringRef s = {"asdf", 4};
18   take_stringref(s);
19 }
20 // CHECK: define {{(dso_local )?}}void @callit()
21 // CHECK: call {{(x86_64_sysvcc )?}}void @take_stringref(ptr {{[^,]*}}, i64 {{[^,]*}})
22 // CHECK: declare {{(dso_local )?}}{{(x86_64_sysvcc )?}}void @take_stringref(ptr, i64)
23 
24 // Check that we pass vectors directly if the target feature is enabled, and
25 // not otherwise.
26 typedef __attribute__((vector_size(32))) float my_m256;
27 typedef __attribute__((vector_size(64))) float my_m512;
28 
29 my_m256 SYSV_CC get_m256(void);
30 void SYSV_CC take_m256(my_m256);
31 my_m512 SYSV_CC get_m512(void);
32 void SYSV_CC take_m512(my_m512);
33 
use_vectors(void)34 void use_vectors(void) {
35   my_m256 v1 = get_m256();
36   take_m256(v1);
37   my_m512 v2 = get_m512();
38   take_m512(v2);
39 }
40 
41 // CHECK: define {{(dso_local )?}}void @use_vectors()
42 // AVX: call {{(x86_64_sysvcc )?}}<8 x float> @get_m256()
43 // AVX: call {{(x86_64_sysvcc )?}}void @take_m256(<8 x float> noundef %{{.*}})
44 // AVX: call {{(x86_64_sysvcc )?}}<16 x float> @get_m512()
45 // AVX: call {{(x86_64_sysvcc )?}}void @take_m512(<16 x float> noundef %{{.*}})
46 // NOAVX: call {{(x86_64_sysvcc )?}}<8 x float> @get_m256()
47 // NOAVX: call {{(x86_64_sysvcc )?}}void @take_m256(ptr noundef byval(<8 x float>) align 32 %{{.*}})
48 // NOAVX: call {{(x86_64_sysvcc )?}}<16 x float> @get_m512()
49 // NOAVX: call {{(x86_64_sysvcc )?}}void @take_m512(ptr noundef byval(<16 x float>) align 64 %{{.*}})
50