xref: /llvm-project/llvm/test/CodeGen/X86/sincos-opt.ll (revision ac2ad3b7bb920598ed6366eba23f157039927639)
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
10
11; Combine sin / cos into a single call unless they may write errno (as
12; captured by readnone attrbiute, controlled by clang -fmath-errno
13; setting).
14; rdar://13087969
15; rdar://13599493
16
17define float @test1(float %x) nounwind {
18entry:
19; GNU_SINCOS-LABEL: test1:
20; GNU_SINCOS: callq sincosf
21; GNU_SINCOS: movss 4(%rsp), %xmm0
22; GNU_SINCOS: addss (%rsp), %xmm0
23
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
28
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
33
34; OSX_NOOPT-LABEL: test1:
35; OSX_NOOPT: callq _sinf
36; OSX_NOOPT: callq _cosf
37
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
45  ret float %add
46}
47
48define float @test1_errno(float %x) nounwind {
49entry:
50; GNU_SINCOS-LABEL: test1_errno:
51; GNU_SINCOS: callq sinf
52; GNU_SINCOS: callq cosf
53
54; GNU_SINCOS_FASTMATH-LABEL: test1_errno:
55; GNU_SINCOS_FASTMATH: callq sinf
56; GNU_SINCOS_FASTMATH: callq cosf
57
58; OSX_SINCOS-LABEL: test1_errno:
59; OSX_SINCOS: callq _sinf
60; OSX_SINCOS: callq _cosf
61
62; OSX_NOOPT-LABEL: test1_errno:
63; OSX_NOOPT: callq _sinf
64; OSX_NOOPT: callq _cosf
65
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
72  ret float %add
73}
74
75define double @test2(double %x) nounwind {
76entry:
77; GNU_SINCOS-LABEL: test2:
78; GNU_SINCOS: callq sincos
79; GNU_SINCOS: movsd 16(%rsp), %xmm0
80; GNU_SINCOS: addsd 8(%rsp), %xmm0
81
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
86
87; OSX_SINCOS-LABEL: test2:
88; OSX_SINCOS: callq ___sincos_stret
89; OSX_SINCOS: addsd %xmm1, %xmm0
90
91; OSX_NOOPT-LABEL: test2:
92; OSX_NOOPT: callq _sin
93; OSX_NOOPT: callq _cos
94
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
102  ret double %add
103}
104
105define double @test2_errno(double %x) nounwind {
106entry:
107; GNU_SINCOS-LABEL: test2_errno:
108; GNU_SINCOS: callq sin
109; GNU_SINCOS: callq cos
110
111; GNU_SINCOS_FASTMATH-LABEL: test2_errno:
112; GNU_SINCOS_FASTMATH: callq sin
113; GNU_SINCOS_FASTMATH: callq cos
114
115; OSX_SINCOS-LABEL: test2_errno:
116; OSX_SINCOS: callq _sin
117; OSX_SINCOS: callq _cos
118
119; OSX_NOOPT-LABEL: test2_errno:
120; OSX_NOOPT: callq _sin
121; OSX_NOOPT: callq _cos
122
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
129  ret double %add
130}
131
132define x86_fp80 @test3(x86_fp80 %x) nounwind {
133entry:
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)
139
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)
145
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
152  ret x86_fp80 %add
153}
154
155define x86_fp80 @test3_errno(x86_fp80 %x) nounwind {
156entry:
157; GNU_SINCOS-LABEL: test3_errno:
158; GNU_SINCOS: callq sinl
159; GNU_SINCOS: callq cosl
160
161; GNU_SINCOS_FASTMATH-LABEL: test3_errno:
162; GNU_SINCOS_FASTMATH: callq sinl
163; GNU_SINCOS_FASTMATH: callq cosl
164
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
171  ret x86_fp80 %add
172}
173
174declare float  @sinf(float)
175declare double @sin(double)
176declare float @cosf(float)
177declare double @cos(double)
178declare x86_fp80 @sinl(x86_fp80)
179declare x86_fp80 @cosl(x86_fp80)
180