bd8f03653cb9eb9829b58f517692700fb2de747f
[oota-llvm.git] / test / Transforms / InstCombine / double-float-shrink-1.ll
1 ; RUN: opt < %s -instcombine -S | FileCheck %s
2
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"
5
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
11
12 ; FIXME: For all tests where the call shrinks, the 'fast' attribute on the call inst should be propagated to the new call.
13
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
18    ret float %conv1
19 ; CHECK-LABEL: acos_test1
20 ; CHECK: call float @acosf(float %f)
21 }
22
23 define double @acos_test2(float %f)   {
24    %conv = fpext float %f to double
25    %call = call fast double @acos(double %conv)
26    ret double %call
27 ; CHECK-LABEL: acos_test2
28 ; CHECK: call fast double @acos(double %conv)
29 }
30
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
35    ret float %conv1
36 ; CHECK-LABEL: acosh_test1
37 ; CHECK: call float @acoshf(float %f)
38 }
39
40 define double @acosh_test2(float %f)   {
41    %conv = fpext float %f to double
42    %call = call fast double @acosh(double %conv)
43    ret double %call
44 ; CHECK-LABEL: acosh_test2
45 ; CHECK: call fast double @acosh(double %conv)
46 }
47
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
52    ret float %conv1
53 ; CHECK-LABEL: asin_test1
54 ; CHECK: call float @asinf(float %f)
55 }
56
57 define double @asin_test2(float %f)   {
58    %conv = fpext float %f to double
59    %call = call fast double @asin(double %conv)
60    ret double %call
61 ; CHECK-LABEL: asin_test2
62 ; CHECK: call fast double @asin(double %conv)
63 }
64
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
69    ret float %conv1
70 ; CHECK-LABEL: asinh_test1
71 ; CHECK: call float @asinhf(float %f)
72 }
73
74 define double @asinh_test2(float %f)   {
75    %conv = fpext float %f to double
76    %call = call fast double @asinh(double %conv)
77    ret double %call
78 ; CHECK-LABEL: asinh_test2
79 ; CHECK: call fast double @asinh(double %conv)
80 }
81
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
86    ret float %conv1
87 ; CHECK-LABEL: atan_test1
88 ; CHECK: call float @atanf(float %f)
89 }
90
91 define double @atan_test2(float %f)   {
92    %conv = fpext float %f to double
93    %call = call fast double @atan(double %conv)
94    ret double %call
95 ; CHECK-LABEL: atan_test2
96 ; CHECK: call fast double @atan(double %conv)
97 }
98
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
103    ret float %conv1
104 ; CHECK-LABEL: atanh_test1
105 ; CHECK: call float @atanhf(float %f)
106 }
107
108 define double @atanh_test2(float %f)   {
109     %conv = fpext float %f to double
110     %call = call fast double @atanh(double %conv)
111     ret double %call
112 ; CHECK-LABEL: atanh_test2
113 ; CHECK: call fast double @atanh(double %conv)
114 }
115
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
120    ret float %conv1
121 ; CHECK-LABEL: cbrt_test1
122 ; CHECK: call float @cbrtf(float %f)
123 }
124
125 define double @cbrt_test2(float %f)   {
126    %conv = fpext float %f to double
127    %call = call fast  double @cbrt(double %conv)
128    ret double %call
129 ; CHECK-LABEL: cbrt_test2
130 ; CHECK: call fast double @cbrt(double %conv)
131 }
132
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
137    ret float %conv1
138 ; CHECK-LABEL: exp_test1
139 ; CHECK: call float @expf(float %f)
140 }
141
142 define double @exp_test2(float %f)   {
143    %conv = fpext float %f to double
144    %call = call fast double @exp(double %conv)
145    ret double %call
146 ; CHECK-LABEL: exp_test2
147 ; CHECK: call fast double @exp(double %conv)
148 }
149
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
154    ret float %conv1
155 ; CHECK-LABEL: expm1_test1
156 ; CHECK: call float @expm1f(float %f)
157 }
158
159 define double @expm1_test2(float %f)   {
160    %conv = fpext float %f to double
161    %call = call fast double @expm1(double %conv)
162    ret double %call
163 ; CHECK-LABEL: expm1_test2
164 ; CHECK: call fast double @expm1(double %conv)
165 }
166
167 ; exp10f() doesn't exist for this triple, so it doesn't shrink.
168
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
173    ret float %conv1
174 ; CHECK-LABEL: exp10_test1
175 ; CHECK: call fast double @exp10(double %conv)
176 }
177
178 define double @exp10_test2(float %f)   {
179    %conv = fpext float %f to double
180    %call = call fast double @exp10(double %conv)
181    ret double %call
182 ; CHECK-LABEL: exp10_test2
183 ; CHECK: call fast double @exp10(double %conv)
184 }
185
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
190    ret float %conv1
191 ; CHECK-LABEL: log_test1
192 ; CHECK: call float @logf(float %f)
193 }
194
195 define double @log_test2(float %f)   {
196    %conv = fpext float %f to double
197    %call = call fast double @log(double %conv)
198    ret double %call
199 ; CHECK-LABEL: log_test2
200 ; CHECK: call fast double @log(double %conv)
201 }
202
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
207    ret float %conv1
208 ; CHECK-LABEL: log10_test1
209 ; CHECK: call float @log10f(float %f)
210 }
211
212 define double @log10_test2(float %f) {
213    %conv = fpext float %f to double
214    %call = call fast double @log10(double %conv)
215    ret double %call
216 ; CHECK-LABEL: log10_test2
217 ; CHECK: call fast double @log10(double %conv)
218 }
219
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
224    ret float %conv1
225 ; CHECK-LABEL: log1p_test1
226 ; CHECK: call float @log1pf(float %f)
227 }
228
229 define double @log1p_test2(float %f)   {
230    %conv = fpext float %f to double
231    %call = call fast double @log1p(double %conv)
232    ret double %call
233 ; CHECK-LABEL: log1p_test2
234 ; CHECK: call fast double @log1p(double %conv)
235 }
236
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
241    ret float %conv1
242 ; CHECK-LABEL: log2_test1
243 ; CHECK: call float @log2f(float %f)
244 }
245
246 define double @log2_test2(float %f)   {
247    %conv = fpext float %f to double
248    %call = call fast double @log2(double %conv)
249    ret double %call
250 ; CHECK-LABEL: log2_test2
251 ; CHECK: call fast double @log2(double %conv)
252 }
253
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
258    ret float %conv1
259 ; CHECK-LABEL: logb_test1
260 ; CHECK: call float @logbf(float %f)
261 }
262
263 define double @logb_test2(float %f)   {
264    %conv = fpext float %f to double
265    %call = call fast double @logb(double %conv)
266    ret double %call
267 ; CHECK-LABEL: logb_test2
268 ; CHECK: call fast double @logb(double %conv)
269 }
270
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
275    ret float %conv1
276 ; CHECK-LABEL: sin_test1
277 ; CHECK: call float @sinf(float %f)
278 }
279
280 define double @sin_test2(float %f) {
281    %conv = fpext float %f to double
282    %call = call fast double @sin(double %conv)
283    ret double %call
284 ; CHECK-LABEL: sin_test2
285 ; CHECK: call fast double @sin(double %conv)
286 }
287
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
292    ret float %conv1
293 ; CHECK-LABEL: sqrt_test1
294 ; CHECK: call float @sqrtf(float %f)
295 }
296
297 define double @sqrt_test2(float %f) {
298    %conv = fpext float %f to double
299    %call = call double @sqrt(double %conv)
300    ret double %call
301 ; CHECK-LABEL: sqrt_test2
302 ; CHECK: call double @sqrt(double %conv)
303 }
304
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
309    ret float %conv1
310 ; CHECK-LABEL: sqrt_int_test1
311 ; CHECK: call float @llvm.sqrt.f32(float %f)
312 }
313
314 define double @sqrt_int_test2(float %f) {
315    %conv = fpext float %f to double
316    %call = call double @llvm.sqrt.f64(double %conv)
317    ret double %call
318 ; CHECK-LABEL: sqrt_int_test2
319 ; CHECK: call double @llvm.sqrt.f64(double %conv)
320 }
321
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
326    ret float %conv1
327 ; CHECK-LABEL: tan_test1
328 ; CHECK: call float @tanf(float %f)
329 }
330
331 define double @tan_test2(float %f) {
332    %conv = fpext float %f to double
333    %call = call fast double @tan(double %conv)
334    ret double %call
335 ; CHECK-LABEL: tan_test2
336 ; CHECK: call fast double @tan(double %conv)
337 }
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
342    ret float %conv1
343 ; CHECK-LABEL: tanh_test1
344 ; CHECK: call float @tanhf(float %f)
345 }
346
347 define double @tanh_test2(float %f) {
348    %conv = fpext float %f to double
349    %call = call fast double @tanh(double %conv)
350    ret double %call
351 ; CHECK-LABEL: tanh_test2
352 ; CHECK: call fast double @tanh(double %conv)
353 }
354
355 declare double @tanh(double) #1
356 declare double @tan(double) #1
357
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) 
362
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
379
380 attributes #1 = { "unsafe-fp-math"="true" }
381