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
9 ; Combine sin / cos into a single call unless they may write errno (as
10 ; captured by readnone attrbiute, controlled by clang -fmath-errno
15 define float @test1(float %x) nounwind {
17 ; GNU_SINCOS-LABEL: test1:
18 ; GNU_SINCOS: callq sincosf
19 ; GNU_SINCOS: movss 4(%rsp), %xmm0
20 ; GNU_SINCOS: addss (%rsp), %xmm0
22 ; GNU_SINCOS_FASTMATH-LABEL: test1:
23 ; GNU_SINCOS_FASTMATH: callq sincosf
24 ; GNU_SINCOS_FASTMATH: movss 4(%{{[re]}}sp), %xmm0
25 ; GNU_SINCOS_FASTMATH: addss (%{{[re]}}sp), %xmm0
27 ; OSX_SINCOS-LABEL: test1:
28 ; OSX_SINCOS: callq ___sincosf_stret
29 ; OSX_SINCOS: movshdup {{.*}} xmm1 = xmm0[1,1,3,3]
30 ; OSX_SINCOS: addss %xmm1, %xmm0
32 ; OSX_NOOPT-LABEL: test1:
33 ; OSX_NOOPT: callq _sinf
34 ; OSX_NOOPT: callq _cosf
35 %call = tail call float @sinf(float %x) readnone
36 %call1 = tail call float @cosf(float %x) readnone
37 %add = fadd float %call, %call1
41 define float @test1_errno(float %x) nounwind {
43 ; GNU_SINCOS-LABEL: test1_errno:
44 ; GNU_SINCOS: callq sinf
45 ; GNU_SINCOS: callq cosf
47 ; GNU_SINCOS_FASTMATH-LABEL: test1_errno:
48 ; GNU_SINCOS_FASTMATH: callq sinf
49 ; GNU_SINCOS_FASTMATH: callq cosf
51 ; OSX_SINCOS-LABEL: test1_errno:
52 ; OSX_SINCOS: callq _sinf
53 ; OSX_SINCOS: callq _cosf
55 ; OSX_NOOPT-LABEL: test1_errno:
56 ; OSX_NOOPT: callq _sinf
57 ; OSX_NOOPT: callq _cosf
58 %call = tail call float @sinf(float %x)
59 %call1 = tail call float @cosf(float %x)
60 %add = fadd float %call, %call1
64 define double @test2(double %x) nounwind {
66 ; GNU_SINCOS-LABEL: test2:
67 ; GNU_SINCOS: callq sincos
68 ; GNU_SINCOS: movsd 16(%rsp), %xmm0
69 ; GNU_SINCOS: addsd 8(%rsp), %xmm0
71 ; GNU_SINCOS_FASTMATH-LABEL: test2:
72 ; GNU_SINCOS_FASTMATH: callq sincos
73 ; GNU_SINCOS_FASTMATH: movsd 16(%{{[re]}}sp), %xmm0
74 ; GNU_SINCOS_FASTMATH: addsd 8(%{{[re]}}sp), %xmm0
76 ; OSX_SINCOS-LABEL: test2:
77 ; OSX_SINCOS: callq ___sincos_stret
78 ; OSX_SINCOS: addsd %xmm1, %xmm0
80 ; OSX_NOOPT-LABEL: test2:
81 ; OSX_NOOPT: callq _sin
82 ; OSX_NOOPT: callq _cos
83 %call = tail call double @sin(double %x) readnone
84 %call1 = tail call double @cos(double %x) readnone
85 %add = fadd double %call, %call1
89 define double @test2_errno(double %x) nounwind {
91 ; GNU_SINCOS-LABEL: test2_errno:
92 ; GNU_SINCOS: callq sin
93 ; GNU_SINCOS: callq cos
95 ; GNU_SINCOS_FASTMATH-LABEL: test2_errno:
96 ; GNU_SINCOS_FASTMATH: callq sin
97 ; GNU_SINCOS_FASTMATH: callq cos
99 ; OSX_SINCOS-LABEL: test2_errno:
100 ; OSX_SINCOS: callq _sin
101 ; OSX_SINCOS: callq _cos
103 ; OSX_NOOPT-LABEL: test2_errno:
104 ; OSX_NOOPT: callq _sin
105 ; OSX_NOOPT: callq _cos
106 %call = tail call double @sin(double %x)
107 %call1 = tail call double @cos(double %x)
108 %add = fadd double %call, %call1
112 define x86_fp80 @test3(x86_fp80 %x) nounwind {
114 ; GNU_SINCOS-LABEL: test3:
115 ; GNU_SINCOS: callq sincosl
116 ; GNU_SINCOS: fldt 16(%rsp)
117 ; GNU_SINCOS: fldt 32(%rsp)
118 ; GNU_SINCOS: faddp %st, %st(1)
120 ; GNU_SINCOS_FASTMATH-LABEL: test3:
121 ; GNU_SINCOS_FASTMATH: callq sincosl
122 ; GNU_SINCOS_FASTMATH: fldt 16(%{{[re]}}sp)
123 ; GNU_SINCOS_FASTMATH: fldt 32(%{{[re]}}sp)
124 ; GNU_SINCOS_FASTMATH: faddp %st, %st(1)
125 %call = tail call x86_fp80 @sinl(x86_fp80 %x) readnone
126 %call1 = tail call x86_fp80 @cosl(x86_fp80 %x) readnone
127 %add = fadd x86_fp80 %call, %call1
131 define x86_fp80 @test3_errno(x86_fp80 %x) nounwind {
133 ; GNU_SINCOS-LABEL: test3_errno:
134 ; GNU_SINCOS: callq sinl
135 ; GNU_SINCOS: callq cosl
137 ; GNU_SINCOS_FASTMATH-LABEL: test3_errno:
138 ; GNU_SINCOS_FASTMATH: callq sinl
139 ; GNU_SINCOS_FASTMATH: callq cosl
140 %call = tail call x86_fp80 @sinl(x86_fp80 %x)
141 %call1 = tail call x86_fp80 @cosl(x86_fp80 %x)
142 %add = fadd x86_fp80 %call, %call1
146 declare float @sinf(float)
147 declare double @sin(double)
148 declare float @cosf(float)
149 declare double @cos(double)
150 declare x86_fp80 @sinl(x86_fp80)
151 declare x86_fp80 @cosl(x86_fp80)