1 // RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=i386-pc-win32 | FileCheck %s --check-prefixes=X86,Win32
2 // RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=x86_64-pc-win32 | FileCheck %s --check-prefixes=X64,Win64
3 // RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=i386-pc-linux-gnu | FileCheck %s --check-prefixes=X86,Lin32
4 // RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=x86_64-pc-linux-gnu | FileCheck %s --check-prefixes=X64,Lin64
5
6 #include <xmmintrin.h>
7
v1(int a,int b)8 void __regcall v1(int a, int b) {}
9 // X86: define dso_local x86_regcallcc void @__regcall3__v1(i32 inreg noundef %a, i32 inreg noundef %b)
10 // X64: define dso_local x86_regcallcc void @__regcall3__v1(i32 noundef %a, i32 noundef %b)
11
v1b(int a,int b)12 void __attribute__((regcall)) v1b(int a, int b) {}
13 // X86: define dso_local x86_regcallcc void @__regcall3__v1b(i32 inreg noundef %a, i32 inreg noundef %b)
14 // X64: define dso_local x86_regcallcc void @__regcall3__v1b(i32 noundef %a, i32 noundef %b)
15
v2(char a,char b)16 void __regcall v2(char a, char b) {}
17 // X86: define dso_local x86_regcallcc void @__regcall3__v2(i8 inreg noundef signext %a, i8 inreg noundef signext %b)
18 // Win64: define dso_local x86_regcallcc void @__regcall3__v2(i8 noundef %a, i8 noundef %b)
19 // Lin64: define dso_local x86_regcallcc void @__regcall3__v2(i8 noundef signext %a, i8 noundef signext %b)
20
21 struct Small { int x; };
v3(int a,struct Small b,int c)22 void __regcall v3(int a, struct Small b, int c) {}
23 // Win32: define dso_local x86_regcallcc void @__regcall3__v3(i32 inreg noundef %a, i32 %b.0, i32 inreg noundef %c)
24 // Lin32: define dso_local x86_regcallcc void @__regcall3__v3(i32 inreg noundef %a, i32 inreg %0, i32 %b.0, i32 inreg noundef %c)
25 // X64: define dso_local x86_regcallcc void @__regcall3__v3(i32 noundef %a, i32 %b.coerce, i32 noundef %c)
26
27 struct Large { int a[5]; };
v4(int a,struct Large b,int c)28 void __regcall v4(int a, struct Large b, int c) {}
29 // Win32: define dso_local x86_regcallcc void @__regcall3__v4(i32 inreg noundef %a, ptr noundef byval(%struct.Large) align 4 %b, i32 inreg noundef %c)
30 // Lin32: define dso_local x86_regcallcc void @__regcall3__v4(i32 inreg noundef %a, ptr noundef byval(%struct.Large) align 4 %b, i32 noundef %c)
31 // Win64: define dso_local x86_regcallcc void @__regcall3__v4(i32 noundef %a, ptr noundef %b, i32 noundef %c)
32 // Lin64: define dso_local x86_regcallcc void @__regcall3__v4(i32 noundef %a, [5 x i32] %b.coerce, i32 noundef %c)
33
v5(long long a,int b,int c)34 void __regcall v5(long long a, int b, int c) {}
35 // X86: define dso_local x86_regcallcc void @__regcall3__v5(i64 noundef %a, i32 inreg noundef %b, i32 inreg noundef %c)
36 // X64: define dso_local x86_regcallcc void @__regcall3__v5(i64 noundef %a, i32 noundef %b, i32 noundef %c)
37
38 struct HFA2 { double x, y; };
39 struct HFA4 { double w, x, y, z; };
40 struct HFA5 { double v, w, x, y, z; };
41
hfa1(int a,struct HFA4 b,int c)42 void __regcall hfa1(int a, struct HFA4 b, int c) {}
43 // X86: define dso_local x86_regcallcc void @__regcall3__hfa1(i32 inreg noundef %a, double %b.0, double %b.1, double %b.2, double %b.3, i32 inreg noundef %c)
44 // X64: define dso_local x86_regcallcc void @__regcall3__hfa1(i32 noundef %a, double %{{.*}}, double %{{.*}}, double %{{.*}}, double %{{.*}}, i32 noundef %c)
45
46 // HFAs that would require more than six total SSE registers are passed
47 // indirectly. Additional vector arguments can consume the rest of the SSE
48 // registers.
hfa2(struct HFA4 a,struct HFA4 b,double c)49 void __regcall hfa2(struct HFA4 a, struct HFA4 b, double c) {}
50 // X86: define dso_local x86_regcallcc void @__regcall3__hfa2(double %a.0, double %a.1, double %a.2, double %a.3, double %b.0, double %b.1, double %b.2, double %b.3, ptr inreg noundef %0)
51 // X64: define dso_local x86_regcallcc void @__regcall3__hfa2(double %{{.*}}, double %{{.*}}, double %{{.*}}, double %{{.*}}, double %{{.*}}, double %{{.*}}, double %{{.*}}, double %{{.*}}, double noundef %c)
52
53 // Ensure that we pass builtin types directly while counting them against the
54 // SSE register usage.
hfa3(double a,double b,double c,double d,double e,struct HFA2 f)55 void __regcall hfa3(double a, double b, double c, double d, double e, struct HFA2 f) {}
56 // X86: define dso_local x86_regcallcc void @__regcall3__hfa3(double noundef %a, double noundef %b, double noundef %c, double noundef %d, double noundef %e, double %f.0, double %f.1)
57 // X64: define dso_local x86_regcallcc void @__regcall3__hfa3(double noundef %a, double noundef %b, double noundef %c, double noundef %d, double noundef %e, double %{{.*}}, double %{{.*}})
58
59 // Aggregates with more than four elements are not HFAs and are passed byval(%b.3, double noundef).
60 // Because they are not classified as homogeneous, they don't get special
61 // handling to ensure alignment.
hfa4(struct HFA5 a)62 void __regcall hfa4(struct HFA5 a) {}
63 // X32: define dso_local x86_regcallcc void @__regcall3__hfa4(ptr noundef byval(%struct.HFA5) align 4 %{{.*}})
64 // Win64: define dso_local x86_regcallcc void @__regcall3__hfa4(ptr noundef %a)
65 // Lin64: define dso_local x86_regcallcc void @__regcall3__hfa4(double %a.coerce0, double %a.coerce1, double %a.coerce2, double %a.coerce3, double %a.coerce4)
66
67 // Return HFAs of 4 or fewer elements in registers.
68 static struct HFA2 g_hfa2;
hfa5(void)69 struct HFA2 __regcall hfa5(void) { return g_hfa2; }
70 // X86: define dso_local x86_regcallcc %struct.HFA2 @__regcall3__hfa5()
71 // X64: define dso_local x86_regcallcc %struct.HFA2 @__regcall3__hfa5()
72
73 typedef float __attribute__((vector_size(16))) v4f32;
74 struct HVA2 { v4f32 x, y; };
75 struct HVA4 { v4f32 w, x, y, z; };
76
hva1(int a,struct HVA4 b,int c)77 void __regcall hva1(int a, struct HVA4 b, int c) {}
78 // X86: define dso_local x86_regcallcc void @__regcall3__hva1(i32 inreg noundef %a, <4 x float> %b.0, <4 x float> %b.1, <4 x float> %b.2, <4 x float> %b.3, i32 inreg noundef %c)
79 // X64: define dso_local x86_regcallcc void @__regcall3__hva1(i32 noundef %a, <4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}}, i32 noundef %c)
80
hva2(struct HVA4 a,struct HVA4 b,v4f32 c)81 void __regcall hva2(struct HVA4 a, struct HVA4 b, v4f32 c) {}
82 // X86: define dso_local x86_regcallcc void @__regcall3__hva2(<4 x float> %a.0, <4 x float> %a.1, <4 x float> %a.2, <4 x float> %a.3, <4 x float> %b.0, <4 x float> %b.1, <4 x float> %b.2, <4 x float> %b.3, ptr inreg noundef %0)
83 // X64: define dso_local x86_regcallcc void @__regcall3__hva2(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> noundef %c)
84
hva3(v4f32 a,v4f32 b,v4f32 c,v4f32 d,v4f32 e,struct HVA2 f)85 void __regcall hva3(v4f32 a, v4f32 b, v4f32 c, v4f32 d, v4f32 e, struct HVA2 f) {}
86 // X86: define dso_local x86_regcallcc void @__regcall3__hva3(<4 x float> noundef %a, <4 x float> noundef %b, <4 x float> noundef %c, <4 x float> noundef %d, <4 x float> noundef %e, <4 x float> %f.0, <4 x float> %f.1)
87 // X64: define dso_local x86_regcallcc void @__regcall3__hva3(<4 x float> noundef %a, <4 x float> noundef %b, <4 x float> noundef %c, <4 x float> noundef %d, <4 x float> noundef %e, <4 x float> %{{.*}}, <4 x float> %{{.*}})
88
89 typedef float __attribute__((ext_vector_type(3))) v3f32;
90 struct OddSizeHVA { v3f32 x, y; };
91
odd_size_hva(struct OddSizeHVA a)92 void __regcall odd_size_hva(struct OddSizeHVA a) {}
93 // X86: define dso_local x86_regcallcc void @__regcall3__odd_size_hva(<3 x float> %a.0, <3 x float> %a.1)
94 // X64: define dso_local x86_regcallcc void @__regcall3__odd_size_hva(<3 x float> %{{.*}}, <3 x float> %{{.*}})
95
96 struct HFA6 { __m128 f[4]; };
ret_reg_reused(struct HFA6 a,struct HFA6 b,struct HFA6 c,struct HFA6 d)97 struct HFA6 __regcall ret_reg_reused(struct HFA6 a, struct HFA6 b, struct HFA6 c, struct HFA6 d){ struct HFA6 h; return h;}
98 // X86: define dso_local x86_regcallcc %struct.HFA6 @__regcall3__ret_reg_reused(<4 x float> %a.0, <4 x float> %a.1, <4 x float> %a.2, <4 x float> %a.3, <4 x float> %b.0, <4 x float> %b.1, <4 x float> %b.2, <4 x float> %b.3, ptr inreg noundef %c, ptr inreg noundef %d)
99 // Win64: define dso_local x86_regcallcc %struct.HFA6 @__regcall3__ret_reg_reused(<4 x float> %a.0, <4 x float> %a.1, <4 x float> %a.2, <4 x float> %a.3, <4 x float> %b.0, <4 x float> %b.1, <4 x float> %b.2, <4 x float> %b.3, <4 x float> %c.0, <4 x float> %c.1, <4 x float> %c.2, <4 x float> %c.3, <4 x float> %d.0, <4 x float> %d.1, <4 x float> %d.2, <4 x float> %d.3)
100 // Lin64: define dso_local x86_regcallcc %struct.HFA6 @__regcall3__ret_reg_reused([4 x <4 x float>] %a.coerce, [4 x <4 x float>] %b.coerce, [4 x <4 x float>] %c.coerce, [4 x <4 x float>] %d.coerce)
101