1 ; RUN: llc < %s -mtriple=x86_64-apple-macosx10.9.0 -mcpu=core2 | FileCheck %s --check-prefix=OSX_SINCOS
2 ; RUN: llc < %s -mtriple=x86_64-apple-macosx10.8.0 -mcpu=core2 | FileCheck %s --check-prefix=OSX_NOOPT
3 ; RUN: llc < %s -mtriple=x86_64-pc-linux-gnu -mcpu=core2 | FileCheck %s --check-prefix=GNU_SINCOS
4 ; RUN: llc < %s -mtriple=x86_64-pc-linux-gnu -mcpu=core2 -enable-unsafe-fp-math | FileCheck %s --check-prefix=GNU_SINCOS_FASTMATH
5 ; RUN: llc < %s -mtriple=x86_64-pc-linux-gnux32 -mcpu=core2 -enable-unsafe-fp-math | FileCheck %s --check-prefix=GNU_SINCOS_FASTMATH
6 ; RUN: llc < %s -mtriple=x86_64-fuchsia -mcpu=core2 | FileCheck %s --check-prefix=GNU_SINCOS
7 ; RUN: llc < %s -mtriple=x86_64-fuchsia -mcpu=core2 -enable-unsafe-fp-math | FileCheck %s --check-prefix=GNU_SINCOS_FASTMATH
8 ; RUN: llc < %s -mtriple=x86_64-scei-ps4 -mcpu=btver2 | FileCheck %s --check-prefix=PS4_SINCOS
9 ; RUN: llc < %s -mtriple=x86_64-sie-ps5 -mcpu=znver2 | FileCheck %s --check-prefix=PS4_SINCOS
11 ; Combine sin / cos into a single call unless they may write errno (as
12 ; captured by readnone attrbiute, controlled by clang -fmath-errno
17 define float @test1(float %x) nounwind {
19 ; GNU_SINCOS-LABEL: test1:
20 ; GNU_SINCOS: callq sincosf
21 ; GNU_SINCOS: movss 4(%rsp), %xmm0
22 ; GNU_SINCOS: addss (%rsp), %xmm0
24 ; GNU_SINCOS_FASTMATH-LABEL: test1:
25 ; GNU_SINCOS_FASTMATH: callq sincosf
26 ; GNU_SINCOS_FASTMATH: movss 4(%{{[re]}}sp), %xmm0
27 ; GNU_SINCOS_FASTMATH: addss (%{{[re]}}sp), %xmm0
29 ; OSX_SINCOS-LABEL: test1:
30 ; OSX_SINCOS: callq ___sincosf_stret
31 ; OSX_SINCOS: movshdup {{.*}} xmm1 = xmm0[1,1,3,3]
32 ; OSX_SINCOS: addss %xmm1, %xmm0
34 ; OSX_NOOPT-LABEL: test1:
35 ; OSX_NOOPT: callq _sinf
36 ; OSX_NOOPT: callq _cosf
38 ; PS4_SINCOS-LABEL: test1:
39 ; PS4_SINCOS: callq sincosf
40 ; PS4_SINCOS: vmovss 4(%rsp), %xmm0
41 ; PS4_SINCOS: vaddss (%rsp), %xmm0, %xmm0
42 %call = tail call float @sinf(float %x) readnone
43 %call1 = tail call float @cosf(float %x) readnone
44 %add = fadd float %call, %call1
48 define float @test1_errno(float %x) nounwind {
50 ; GNU_SINCOS-LABEL: test1_errno:
51 ; GNU_SINCOS: callq sinf
52 ; GNU_SINCOS: callq cosf
54 ; GNU_SINCOS_FASTMATH-LABEL: test1_errno:
55 ; GNU_SINCOS_FASTMATH: callq sinf
56 ; GNU_SINCOS_FASTMATH: callq cosf
58 ; OSX_SINCOS-LABEL: test1_errno:
59 ; OSX_SINCOS: callq _sinf
60 ; OSX_SINCOS: callq _cosf
62 ; OSX_NOOPT-LABEL: test1_errno:
63 ; OSX_NOOPT: callq _sinf
64 ; OSX_NOOPT: callq _cosf
66 ; PS4_SINCOS-LABEL: test1_errno:
67 ; PS4_SINCOS: callq sinf
68 ; PS4_SINCOS: callq cosf
69 %call = tail call float @sinf(float %x)
70 %call1 = tail call float @cosf(float %x)
71 %add = fadd float %call, %call1
75 define double @test2(double %x) nounwind {
77 ; GNU_SINCOS-LABEL: test2:
78 ; GNU_SINCOS: callq sincos
79 ; GNU_SINCOS: movsd 16(%rsp), %xmm0
80 ; GNU_SINCOS: addsd 8(%rsp), %xmm0
82 ; GNU_SINCOS_FASTMATH-LABEL: test2:
83 ; GNU_SINCOS_FASTMATH: callq sincos
84 ; GNU_SINCOS_FASTMATH: movsd 16(%{{[re]}}sp), %xmm0
85 ; GNU_SINCOS_FASTMATH: addsd 8(%{{[re]}}sp), %xmm0
87 ; OSX_SINCOS-LABEL: test2:
88 ; OSX_SINCOS: callq ___sincos_stret
89 ; OSX_SINCOS: addsd %xmm1, %xmm0
91 ; OSX_NOOPT-LABEL: test2:
92 ; OSX_NOOPT: callq _sin
93 ; OSX_NOOPT: callq _cos
95 ; PS4_SINCOS-LABEL: test2:
96 ; PS4_SINCOS: callq sincos
97 ; PS4_SINCOS: vmovsd 16(%rsp), %xmm0
98 ; PS4_SINCOS: vaddsd 8(%rsp), %xmm0, %xmm0
99 %call = tail call double @sin(double %x) readnone
100 %call1 = tail call double @cos(double %x) readnone
101 %add = fadd double %call, %call1
105 define double @test2_errno(double %x) nounwind {
107 ; GNU_SINCOS-LABEL: test2_errno:
108 ; GNU_SINCOS: callq sin
109 ; GNU_SINCOS: callq cos
111 ; GNU_SINCOS_FASTMATH-LABEL: test2_errno:
112 ; GNU_SINCOS_FASTMATH: callq sin
113 ; GNU_SINCOS_FASTMATH: callq cos
115 ; OSX_SINCOS-LABEL: test2_errno:
116 ; OSX_SINCOS: callq _sin
117 ; OSX_SINCOS: callq _cos
119 ; OSX_NOOPT-LABEL: test2_errno:
120 ; OSX_NOOPT: callq _sin
121 ; OSX_NOOPT: callq _cos
123 ; PS4_SINCOS-LABEL: test2_errno:
124 ; PS4_SINCOS: callq sin
125 ; PS4_SINCOS: callq cos
126 %call = tail call double @sin(double %x)
127 %call1 = tail call double @cos(double %x)
128 %add = fadd double %call, %call1
132 define x86_fp80 @test3(x86_fp80 %x) nounwind {
134 ; GNU_SINCOS-LABEL: test3:
135 ; GNU_SINCOS: callq sincosl
136 ; GNU_SINCOS: fldt 16(%rsp)
137 ; GNU_SINCOS: fldt 32(%rsp)
138 ; GNU_SINCOS: faddp %st, %st(1)
140 ; GNU_SINCOS_FASTMATH-LABEL: test3:
141 ; GNU_SINCOS_FASTMATH: callq sincosl
142 ; GNU_SINCOS_FASTMATH: fldt 16(%{{[re]}}sp)
143 ; GNU_SINCOS_FASTMATH: fldt 32(%{{[re]}}sp)
144 ; GNU_SINCOS_FASTMATH: faddp %st, %st(1)
146 ; PS4_SINCOS-LABEL: test3:
147 ; PS4_SINCOS: callq sinl
148 ; PS4_SINCOS: callq cosl
149 %call = tail call x86_fp80 @sinl(x86_fp80 %x) readnone
150 %call1 = tail call x86_fp80 @cosl(x86_fp80 %x) readnone
151 %add = fadd x86_fp80 %call, %call1
155 define x86_fp80 @test3_errno(x86_fp80 %x) nounwind {
157 ; GNU_SINCOS-LABEL: test3_errno:
158 ; GNU_SINCOS: callq sinl
159 ; GNU_SINCOS: callq cosl
161 ; GNU_SINCOS_FASTMATH-LABEL: test3_errno:
162 ; GNU_SINCOS_FASTMATH: callq sinl
163 ; GNU_SINCOS_FASTMATH: callq cosl
165 ; PS4_SINCOS-LABEL: test3_errno:
166 ; PS4_SINCOS: callq sinl
167 ; PS4_SINCOS: callq cosl
168 %call = tail call x86_fp80 @sinl(x86_fp80 %x)
169 %call1 = tail call x86_fp80 @cosl(x86_fp80 %x)
170 %add = fadd x86_fp80 %call, %call1
174 declare float @sinf(float)
175 declare double @sin(double)
176 declare float @cosf(float)
177 declare double @cos(double)
178 declare x86_fp80 @sinl(x86_fp80)
179 declare x86_fp80 @cosl(x86_fp80)