1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s
4 declare float @llvm.pow.f32(float, float)
5 declare <4 x float> @llvm.pow.v4f32(<4 x float>, <4 x float>)
7 declare double @llvm.pow.f64(double, double)
8 declare <2 x double> @llvm.pow.v2f64(<2 x double>, <2 x double>)
10 declare x86_fp80 @llvm.pow.f80(x86_fp80, x86_fp80)
12 define float @pow_f32_one_fourth_fmf(float %x) nounwind {
13 ; CHECK-LABEL: pow_f32_one_fourth_fmf:
15 ; CHECK-NEXT: rsqrtss %xmm0, %xmm1
16 ; CHECK-NEXT: movaps %xmm0, %xmm2
17 ; CHECK-NEXT: mulss %xmm1, %xmm2
18 ; CHECK-NEXT: movss {{.*#+}} xmm3 = mem[0],zero,zero,zero
19 ; CHECK-NEXT: movaps %xmm2, %xmm4
20 ; CHECK-NEXT: mulss %xmm3, %xmm4
21 ; CHECK-NEXT: mulss %xmm1, %xmm2
22 ; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
23 ; CHECK-NEXT: addss %xmm1, %xmm2
24 ; CHECK-NEXT: mulss %xmm4, %xmm2
25 ; CHECK-NEXT: xorps %xmm4, %xmm4
26 ; CHECK-NEXT: cmpeqss %xmm4, %xmm0
27 ; CHECK-NEXT: andnps %xmm2, %xmm0
28 ; CHECK-NEXT: xorps %xmm2, %xmm2
29 ; CHECK-NEXT: rsqrtss %xmm0, %xmm2
30 ; CHECK-NEXT: movaps %xmm0, %xmm5
31 ; CHECK-NEXT: mulss %xmm2, %xmm5
32 ; CHECK-NEXT: mulss %xmm5, %xmm3
33 ; CHECK-NEXT: mulss %xmm2, %xmm5
34 ; CHECK-NEXT: addss %xmm1, %xmm5
35 ; CHECK-NEXT: mulss %xmm3, %xmm5
36 ; CHECK-NEXT: cmpeqss %xmm4, %xmm0
37 ; CHECK-NEXT: andnps %xmm5, %xmm0
39 %r = call nsz ninf afn float @llvm.pow.f32(float %x, float 2.5e-01)
43 define double @pow_f64_one_fourth_fmf(double %x) nounwind {
44 ; CHECK-LABEL: pow_f64_one_fourth_fmf:
46 ; CHECK-NEXT: sqrtsd %xmm0, %xmm0
47 ; CHECK-NEXT: sqrtsd %xmm0, %xmm0
49 %r = call nsz ninf afn double @llvm.pow.f64(double %x, double 2.5e-01)
53 define <4 x float> @pow_v4f32_one_fourth_fmf(<4 x float> %x) nounwind {
54 ; CHECK-LABEL: pow_v4f32_one_fourth_fmf:
56 ; CHECK-NEXT: rsqrtps %xmm0, %xmm1
57 ; CHECK-NEXT: movaps %xmm0, %xmm2
58 ; CHECK-NEXT: mulps %xmm1, %xmm2
59 ; CHECK-NEXT: movaps {{.*#+}} xmm3 = [-5.0E-1,-5.0E-1,-5.0E-1,-5.0E-1]
60 ; CHECK-NEXT: movaps %xmm2, %xmm4
61 ; CHECK-NEXT: mulps %xmm3, %xmm4
62 ; CHECK-NEXT: mulps %xmm1, %xmm2
63 ; CHECK-NEXT: movaps {{.*#+}} xmm1 = [-3.0E+0,-3.0E+0,-3.0E+0,-3.0E+0]
64 ; CHECK-NEXT: addps %xmm1, %xmm2
65 ; CHECK-NEXT: mulps %xmm4, %xmm2
66 ; CHECK-NEXT: xorps %xmm4, %xmm4
67 ; CHECK-NEXT: cmpneqps %xmm4, %xmm0
68 ; CHECK-NEXT: andps %xmm2, %xmm0
69 ; CHECK-NEXT: rsqrtps %xmm0, %xmm2
70 ; CHECK-NEXT: movaps %xmm0, %xmm5
71 ; CHECK-NEXT: mulps %xmm2, %xmm5
72 ; CHECK-NEXT: mulps %xmm5, %xmm3
73 ; CHECK-NEXT: mulps %xmm2, %xmm5
74 ; CHECK-NEXT: addps %xmm1, %xmm5
75 ; CHECK-NEXT: mulps %xmm3, %xmm5
76 ; CHECK-NEXT: cmpneqps %xmm4, %xmm0
77 ; CHECK-NEXT: andps %xmm5, %xmm0
79 %r = call fast <4 x float> @llvm.pow.v4f32(<4 x float> %x, <4 x float> <float 2.5e-1, float 2.5e-1, float 2.5e-01, float 2.5e-01>)
83 define <2 x double> @pow_v2f64_one_fourth_fmf(<2 x double> %x) nounwind {
84 ; CHECK-LABEL: pow_v2f64_one_fourth_fmf:
86 ; CHECK-NEXT: sqrtpd %xmm0, %xmm0
87 ; CHECK-NEXT: sqrtpd %xmm0, %xmm0
89 %r = call fast <2 x double> @llvm.pow.v2f64(<2 x double> %x, <2 x double> <double 2.5e-1, double 2.5e-1>)
93 define float @pow_f32_one_fourth_not_enough_fmf(float %x) nounwind {
94 ; CHECK-LABEL: pow_f32_one_fourth_not_enough_fmf:
96 ; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
97 ; CHECK-NEXT: jmp powf # TAILCALL
98 %r = call afn ninf float @llvm.pow.f32(float %x, float 2.5e-01)
102 define double @pow_f64_one_fourth_not_enough_fmf(double %x) nounwind {
103 ; CHECK-LABEL: pow_f64_one_fourth_not_enough_fmf:
105 ; CHECK-NEXT: movsd {{.*#+}} xmm1 = mem[0],zero
106 ; CHECK-NEXT: jmp pow # TAILCALL
107 %r = call nsz ninf double @llvm.pow.f64(double %x, double 2.5e-01)
111 define <4 x float> @pow_v4f32_one_fourth_not_enough_fmf(<4 x float> %x) nounwind {
112 ; CHECK-LABEL: pow_v4f32_one_fourth_not_enough_fmf:
114 ; CHECK-NEXT: subq $56, %rsp
115 ; CHECK-NEXT: movaps %xmm0, {{[-0-9]+}}(%r{{[sb]}}p) # 16-byte Spill
116 ; CHECK-NEXT: shufps {{.*#+}} xmm0 = xmm0[3,1,2,3]
117 ; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
118 ; CHECK-NEXT: callq powf
119 ; CHECK-NEXT: movaps %xmm0, (%rsp) # 16-byte Spill
120 ; CHECK-NEXT: movaps {{[-0-9]+}}(%r{{[sb]}}p), %xmm0 # 16-byte Reload
121 ; CHECK-NEXT: movhlps {{.*#+}} xmm0 = xmm0[1,1]
122 ; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
123 ; CHECK-NEXT: callq powf
124 ; CHECK-NEXT: unpcklps (%rsp), %xmm0 # 16-byte Folded Reload
125 ; CHECK-NEXT: # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
126 ; CHECK-NEXT: movaps %xmm0, (%rsp) # 16-byte Spill
127 ; CHECK-NEXT: movaps {{[-0-9]+}}(%r{{[sb]}}p), %xmm0 # 16-byte Reload
128 ; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
129 ; CHECK-NEXT: callq powf
130 ; CHECK-NEXT: movaps %xmm0, {{[-0-9]+}}(%r{{[sb]}}p) # 16-byte Spill
131 ; CHECK-NEXT: movaps {{[-0-9]+}}(%r{{[sb]}}p), %xmm0 # 16-byte Reload
132 ; CHECK-NEXT: shufps {{.*#+}} xmm0 = xmm0[1,1,2,3]
133 ; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
134 ; CHECK-NEXT: callq powf
135 ; CHECK-NEXT: movaps {{[-0-9]+}}(%r{{[sb]}}p), %xmm1 # 16-byte Reload
136 ; CHECK-NEXT: unpcklps {{.*#+}} xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
137 ; CHECK-NEXT: unpcklpd (%rsp), %xmm1 # 16-byte Folded Reload
138 ; CHECK-NEXT: # xmm1 = xmm1[0],mem[0]
139 ; CHECK-NEXT: movaps %xmm1, %xmm0
140 ; CHECK-NEXT: addq $56, %rsp
142 %r = call afn nsz <4 x float> @llvm.pow.v4f32(<4 x float> %x, <4 x float> <float 2.5e-1, float 2.5e-1, float 2.5e-01, float 2.5e-01>)
146 define <2 x double> @pow_v2f64_one_fourth_not_enough_fmf(<2 x double> %x) nounwind {
147 ; CHECK-LABEL: pow_v2f64_one_fourth_not_enough_fmf:
149 ; CHECK-NEXT: subq $40, %rsp
150 ; CHECK-NEXT: movaps %xmm0, (%rsp) # 16-byte Spill
151 ; CHECK-NEXT: movsd {{.*#+}} xmm1 = mem[0],zero
152 ; CHECK-NEXT: callq pow
153 ; CHECK-NEXT: movaps %xmm0, {{[-0-9]+}}(%r{{[sb]}}p) # 16-byte Spill
154 ; CHECK-NEXT: movaps (%rsp), %xmm0 # 16-byte Reload
155 ; CHECK-NEXT: movhlps {{.*#+}} xmm0 = xmm0[1,1]
156 ; CHECK-NEXT: movsd {{.*#+}} xmm1 = mem[0],zero
157 ; CHECK-NEXT: callq pow
158 ; CHECK-NEXT: movaps {{[-0-9]+}}(%r{{[sb]}}p), %xmm1 # 16-byte Reload
159 ; CHECK-NEXT: movlhps {{.*#+}} xmm1 = xmm1[0],xmm0[0]
160 ; CHECK-NEXT: movaps %xmm1, %xmm0
161 ; CHECK-NEXT: addq $40, %rsp
163 %r = call nsz nnan reassoc <2 x double> @llvm.pow.v2f64(<2 x double> %x, <2 x double> <double 2.5e-1, double 2.5e-1>)
167 define float @pow_f32_one_third_fmf(float %x) nounwind {
168 ; CHECK-LABEL: pow_f32_one_third_fmf:
170 ; CHECK-NEXT: jmp cbrtf # TAILCALL
171 %one = uitofp i32 1 to float
172 %three = uitofp i32 3 to float
173 %exp = fdiv float %one, %three
174 %r = call nsz nnan ninf afn float @llvm.pow.f32(float %x, float %exp)
178 define double @pow_f64_one_third_fmf(double %x) nounwind {
179 ; CHECK-LABEL: pow_f64_one_third_fmf:
181 ; CHECK-NEXT: jmp cbrt # TAILCALL
182 %one = uitofp i32 1 to double
183 %three = uitofp i32 3 to double
184 %exp = fdiv double %one, %three
185 %r = call nsz nnan ninf afn double @llvm.pow.f64(double %x, double %exp)
189 ; TODO: We could turn this into cbrtl, but currently we only handle float/double types.
191 define x86_fp80 @pow_f80_one_third_fmf(x86_fp80 %x) nounwind {
192 ; CHECK-LABEL: pow_f80_one_third_fmf:
194 ; CHECK-NEXT: subq $40, %rsp
195 ; CHECK-NEXT: fldt {{[0-9]+}}(%rsp)
196 ; CHECK-NEXT: fldt {{.*}}(%rip)
197 ; CHECK-NEXT: fstpt {{[0-9]+}}(%rsp)
198 ; CHECK-NEXT: fstpt (%rsp)
199 ; CHECK-NEXT: callq powl
200 ; CHECK-NEXT: addq $40, %rsp
202 %one = uitofp i32 1 to x86_fp80
203 %three = uitofp i32 3 to x86_fp80
204 %exp = fdiv x86_fp80 %one, %three
205 %r = call nsz nnan ninf afn x86_fp80 @llvm.pow.f80(x86_fp80 %x, x86_fp80 %exp)
209 ; We might want to allow this. The exact hex value for 1/3 as a double is 0x3fd5555555555555.
211 define double @pow_f64_not_exactly_one_third_fmf(double %x) nounwind {
212 ; CHECK-LABEL: pow_f64_not_exactly_one_third_fmf:
214 ; CHECK-NEXT: movsd {{.*#+}} xmm1 = mem[0],zero
215 ; CHECK-NEXT: jmp pow # TAILCALL
216 %r = call nsz nnan ninf afn double @llvm.pow.f64(double %x, double 0x3fd5555555555556)
220 ; We require all 4 of nsz, ninf, nnan, afn.
222 define double @pow_f64_not_enough_fmf(double %x) nounwind {
223 ; CHECK-LABEL: pow_f64_not_enough_fmf:
225 ; CHECK-NEXT: movsd {{.*#+}} xmm1 = mem[0],zero
226 ; CHECK-NEXT: jmp pow # TAILCALL
227 %r = call nsz ninf afn double @llvm.pow.f64(double %x, double 0x3fd5555555555555)