1 ; RUN: opt < %s -instcombine -S | FileCheck %s
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
6 ; Check for and against shrinkage when using the
7 ; unsafe-fp-math function attribute on a math lib
8 ; function. This optimization may be overridden by
9 ; the -enable-double-float-shrink option.
10 ; PR17850: http://llvm.org/bugs/show_bug.cgi?id=17850
12 ; FIXME: For all tests where the call shrinks, the 'fast' attribute on the call inst should be propagated to the new call.
14 define float @acos_test1(float %f) {
15 %conv = fpext float %f to double
16 %call = call fast double @acos(double %conv)
17 %conv1 = fptrunc double %call to float
19 ; CHECK-LABEL: acos_test1
20 ; CHECK: call float @acosf(float %f)
23 define double @acos_test2(float %f) {
24 %conv = fpext float %f to double
25 %call = call fast double @acos(double %conv)
27 ; CHECK-LABEL: acos_test2
28 ; CHECK: call fast double @acos(double %conv)
31 define float @acosh_test1(float %f) {
32 %conv = fpext float %f to double
33 %call = call fast double @acosh(double %conv)
34 %conv1 = fptrunc double %call to float
36 ; CHECK-LABEL: acosh_test1
37 ; CHECK: call float @acoshf(float %f)
40 define double @acosh_test2(float %f) {
41 %conv = fpext float %f to double
42 %call = call fast double @acosh(double %conv)
44 ; CHECK-LABEL: acosh_test2
45 ; CHECK: call fast double @acosh(double %conv)
48 define float @asin_test1(float %f) {
49 %conv = fpext float %f to double
50 %call = call fast double @asin(double %conv)
51 %conv1 = fptrunc double %call to float
53 ; CHECK-LABEL: asin_test1
54 ; CHECK: call float @asinf(float %f)
57 define double @asin_test2(float %f) {
58 %conv = fpext float %f to double
59 %call = call fast double @asin(double %conv)
61 ; CHECK-LABEL: asin_test2
62 ; CHECK: call fast double @asin(double %conv)
65 define float @asinh_test1(float %f) {
66 %conv = fpext float %f to double
67 %call = call fast double @asinh(double %conv)
68 %conv1 = fptrunc double %call to float
70 ; CHECK-LABEL: asinh_test1
71 ; CHECK: call float @asinhf(float %f)
74 define double @asinh_test2(float %f) {
75 %conv = fpext float %f to double
76 %call = call fast double @asinh(double %conv)
78 ; CHECK-LABEL: asinh_test2
79 ; CHECK: call fast double @asinh(double %conv)
82 define float @atan_test1(float %f) {
83 %conv = fpext float %f to double
84 %call = call fast double @atan(double %conv)
85 %conv1 = fptrunc double %call to float
87 ; CHECK-LABEL: atan_test1
88 ; CHECK: call float @atanf(float %f)
91 define double @atan_test2(float %f) {
92 %conv = fpext float %f to double
93 %call = call fast double @atan(double %conv)
95 ; CHECK-LABEL: atan_test2
96 ; CHECK: call fast double @atan(double %conv)
99 define float @atanh_test1(float %f) {
100 %conv = fpext float %f to double
101 %call = call fast double @atanh(double %conv)
102 %conv1 = fptrunc double %call to float
104 ; CHECK-LABEL: atanh_test1
105 ; CHECK: call float @atanhf(float %f)
108 define double @atanh_test2(float %f) {
109 %conv = fpext float %f to double
110 %call = call fast double @atanh(double %conv)
112 ; CHECK-LABEL: atanh_test2
113 ; CHECK: call fast double @atanh(double %conv)
116 define float @cbrt_test1(float %f) {
117 %conv = fpext float %f to double
118 %call = call fast double @cbrt(double %conv)
119 %conv1 = fptrunc double %call to float
121 ; CHECK-LABEL: cbrt_test1
122 ; CHECK: call float @cbrtf(float %f)
125 define double @cbrt_test2(float %f) {
126 %conv = fpext float %f to double
127 %call = call fast double @cbrt(double %conv)
129 ; CHECK-LABEL: cbrt_test2
130 ; CHECK: call fast double @cbrt(double %conv)
133 define float @exp_test1(float %f) {
134 %conv = fpext float %f to double
135 %call = call fast double @exp(double %conv)
136 %conv1 = fptrunc double %call to float
138 ; CHECK-LABEL: exp_test1
139 ; CHECK: call float @expf(float %f)
142 define double @exp_test2(float %f) {
143 %conv = fpext float %f to double
144 %call = call fast double @exp(double %conv)
146 ; CHECK-LABEL: exp_test2
147 ; CHECK: call fast double @exp(double %conv)
150 define float @expm1_test1(float %f) {
151 %conv = fpext float %f to double
152 %call = call fast double @expm1(double %conv)
153 %conv1 = fptrunc double %call to float
155 ; CHECK-LABEL: expm1_test1
156 ; CHECK: call float @expm1f(float %f)
159 define double @expm1_test2(float %f) {
160 %conv = fpext float %f to double
161 %call = call fast double @expm1(double %conv)
163 ; CHECK-LABEL: expm1_test2
164 ; CHECK: call fast double @expm1(double %conv)
167 ; exp10f() doesn't exist for this triple, so it doesn't shrink.
169 define float @exp10_test1(float %f) {
170 %conv = fpext float %f to double
171 %call = call fast double @exp10(double %conv)
172 %conv1 = fptrunc double %call to float
174 ; CHECK-LABEL: exp10_test1
175 ; CHECK: call fast double @exp10(double %conv)
178 define double @exp10_test2(float %f) {
179 %conv = fpext float %f to double
180 %call = call fast double @exp10(double %conv)
182 ; CHECK-LABEL: exp10_test2
183 ; CHECK: call fast double @exp10(double %conv)
186 define float @log_test1(float %f) {
187 %conv = fpext float %f to double
188 %call = call fast double @log(double %conv)
189 %conv1 = fptrunc double %call to float
191 ; CHECK-LABEL: log_test1
192 ; CHECK: call float @logf(float %f)
195 define double @log_test2(float %f) {
196 %conv = fpext float %f to double
197 %call = call fast double @log(double %conv)
199 ; CHECK-LABEL: log_test2
200 ; CHECK: call fast double @log(double %conv)
203 define float @log10_test1(float %f) {
204 %conv = fpext float %f to double
205 %call = call fast double @log10(double %conv)
206 %conv1 = fptrunc double %call to float
208 ; CHECK-LABEL: log10_test1
209 ; CHECK: call float @log10f(float %f)
212 define double @log10_test2(float %f) {
213 %conv = fpext float %f to double
214 %call = call fast double @log10(double %conv)
216 ; CHECK-LABEL: log10_test2
217 ; CHECK: call fast double @log10(double %conv)
220 define float @log1p_test1(float %f) {
221 %conv = fpext float %f to double
222 %call = call fast double @log1p(double %conv)
223 %conv1 = fptrunc double %call to float
225 ; CHECK-LABEL: log1p_test1
226 ; CHECK: call float @log1pf(float %f)
229 define double @log1p_test2(float %f) {
230 %conv = fpext float %f to double
231 %call = call fast double @log1p(double %conv)
233 ; CHECK-LABEL: log1p_test2
234 ; CHECK: call fast double @log1p(double %conv)
237 define float @log2_test1(float %f) {
238 %conv = fpext float %f to double
239 %call = call fast double @log2(double %conv)
240 %conv1 = fptrunc double %call to float
242 ; CHECK-LABEL: log2_test1
243 ; CHECK: call float @log2f(float %f)
246 define double @log2_test2(float %f) {
247 %conv = fpext float %f to double
248 %call = call fast double @log2(double %conv)
250 ; CHECK-LABEL: log2_test2
251 ; CHECK: call fast double @log2(double %conv)
254 define float @logb_test1(float %f) {
255 %conv = fpext float %f to double
256 %call = call fast double @logb(double %conv)
257 %conv1 = fptrunc double %call to float
259 ; CHECK-LABEL: logb_test1
260 ; CHECK: call float @logbf(float %f)
263 define double @logb_test2(float %f) {
264 %conv = fpext float %f to double
265 %call = call fast double @logb(double %conv)
267 ; CHECK-LABEL: logb_test2
268 ; CHECK: call fast double @logb(double %conv)
271 define float @sin_test1(float %f) {
272 %conv = fpext float %f to double
273 %call = call fast double @sin(double %conv)
274 %conv1 = fptrunc double %call to float
276 ; CHECK-LABEL: sin_test1
277 ; CHECK: call float @sinf(float %f)
280 define double @sin_test2(float %f) {
281 %conv = fpext float %f to double
282 %call = call fast double @sin(double %conv)
284 ; CHECK-LABEL: sin_test2
285 ; CHECK: call fast double @sin(double %conv)
288 define float @sqrt_test1(float %f) {
289 %conv = fpext float %f to double
290 %call = call double @sqrt(double %conv)
291 %conv1 = fptrunc double %call to float
293 ; CHECK-LABEL: sqrt_test1
294 ; CHECK: call float @sqrtf(float %f)
297 define double @sqrt_test2(float %f) {
298 %conv = fpext float %f to double
299 %call = call double @sqrt(double %conv)
301 ; CHECK-LABEL: sqrt_test2
302 ; CHECK: call double @sqrt(double %conv)
305 define float @sqrt_int_test1(float %f) {
306 %conv = fpext float %f to double
307 %call = call double @llvm.sqrt.f64(double %conv)
308 %conv1 = fptrunc double %call to float
310 ; CHECK-LABEL: sqrt_int_test1
311 ; CHECK: call float @llvm.sqrt.f32(float %f)
314 define double @sqrt_int_test2(float %f) {
315 %conv = fpext float %f to double
316 %call = call double @llvm.sqrt.f64(double %conv)
318 ; CHECK-LABEL: sqrt_int_test2
319 ; CHECK: call double @llvm.sqrt.f64(double %conv)
322 define float @tan_test1(float %f) {
323 %conv = fpext float %f to double
324 %call = call fast double @tan(double %conv)
325 %conv1 = fptrunc double %call to float
327 ; CHECK-LABEL: tan_test1
328 ; CHECK: call float @tanf(float %f)
331 define double @tan_test2(float %f) {
332 %conv = fpext float %f to double
333 %call = call fast double @tan(double %conv)
335 ; CHECK-LABEL: tan_test2
336 ; CHECK: call fast double @tan(double %conv)
338 define float @tanh_test1(float %f) {
339 %conv = fpext float %f to double
340 %call = call fast double @tanh(double %conv)
341 %conv1 = fptrunc double %call to float
343 ; CHECK-LABEL: tanh_test1
344 ; CHECK: call float @tanhf(float %f)
347 define double @tanh_test2(float %f) {
348 %conv = fpext float %f to double
349 %call = call fast double @tanh(double %conv)
351 ; CHECK-LABEL: tanh_test2
352 ; CHECK: call fast double @tanh(double %conv)
355 declare double @tanh(double) #1
356 declare double @tan(double) #1
358 ; sqrt is a special case: the shrinking optimization
359 ; is valid even without unsafe-fp-math.
360 declare double @sqrt(double)
361 declare double @llvm.sqrt.f64(double)
363 declare double @sin(double) #1
364 declare double @log2(double) #1
365 declare double @log1p(double) #1
366 declare double @log10(double) #1
367 declare double @log(double) #1
368 declare double @logb(double) #1
369 declare double @exp10(double) #1
370 declare double @expm1(double) #1
371 declare double @exp(double) #1
372 declare double @cbrt(double) #1
373 declare double @atanh(double) #1
374 declare double @atan(double) #1
375 declare double @acos(double) #1
376 declare double @acosh(double) #1
377 declare double @asin(double) #1
378 declare double @asinh(double) #1
380 attributes #1 = { "unsafe-fp-math"="true" }