blob: 63a02bbd8572b045d2bfae57f87610ac854ef776 [file] [log] [blame]
Sanjay Patela92fa442014-10-22 15:29:23 +00001; RUN: opt < %s -instcombine -S | FileCheck %s
Meador Inge193e0352012-11-13 04:16:17 +00002
3target 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"
4target triple = "x86_64-unknown-linux-gnu"
5
Sanjay Patela92fa442014-10-22 15:29:23 +00006; 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
12define float @acos_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +000013 %conv = fpext float %f to double
14 %call = call double @acos(double %conv)
15 %conv1 = fptrunc double %call to float
16 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +000017; CHECK-LABEL: acos_test
Meador Inge193e0352012-11-13 04:16:17 +000018; CHECK: call float @acosf(float %f)
19}
20
Sanjay Patela92fa442014-10-22 15:29:23 +000021define double @acos_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +000022 %conv = fpext float %f to double
23 %call = call double @acos(double %conv)
24 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +000025; CHECK-LABEL: acos_test2
Meador Inge193e0352012-11-13 04:16:17 +000026; CHECK: call double @acos(double %conv)
27}
28
Sanjay Patela92fa442014-10-22 15:29:23 +000029define float @acosh_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +000030 %conv = fpext float %f to double
31 %call = call double @acosh(double %conv)
32 %conv1 = fptrunc double %call to float
33 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +000034; CHECK-LABEL: acosh_test
Meador Inge193e0352012-11-13 04:16:17 +000035; CHECK: call float @acoshf(float %f)
36}
37
Sanjay Patela92fa442014-10-22 15:29:23 +000038define double @acosh_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +000039 %conv = fpext float %f to double
40 %call = call double @acosh(double %conv)
41 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +000042; CHECK-LABEL: acosh_test2
Meador Inge193e0352012-11-13 04:16:17 +000043; CHECK: call double @acosh(double %conv)
44}
45
Sanjay Patela92fa442014-10-22 15:29:23 +000046define float @asin_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +000047 %conv = fpext float %f to double
48 %call = call double @asin(double %conv)
49 %conv1 = fptrunc double %call to float
50 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +000051; CHECK-LABEL: asin_test
Meador Inge193e0352012-11-13 04:16:17 +000052; CHECK: call float @asinf(float %f)
53}
54
Sanjay Patela92fa442014-10-22 15:29:23 +000055define double @asin_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +000056 %conv = fpext float %f to double
57 %call = call double @asin(double %conv)
58 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +000059; CHECK-LABEL: asin_test2
Meador Inge193e0352012-11-13 04:16:17 +000060; CHECK: call double @asin(double %conv)
61}
62
Sanjay Patela92fa442014-10-22 15:29:23 +000063define float @asinh_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +000064 %conv = fpext float %f to double
65 %call = call double @asinh(double %conv)
66 %conv1 = fptrunc double %call to float
67 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +000068; CHECK-LABEL: asinh_test
Meador Inge193e0352012-11-13 04:16:17 +000069; CHECK: call float @asinhf(float %f)
70}
71
Sanjay Patela92fa442014-10-22 15:29:23 +000072define double @asinh_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +000073 %conv = fpext float %f to double
74 %call = call double @asinh(double %conv)
75 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +000076; CHECK-LABEL: asinh_test2
Meador Inge193e0352012-11-13 04:16:17 +000077; CHECK: call double @asinh(double %conv)
78}
79
Sanjay Patela92fa442014-10-22 15:29:23 +000080define float @atan_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +000081 %conv = fpext float %f to double
82 %call = call double @atan(double %conv)
83 %conv1 = fptrunc double %call to float
84 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +000085; CHECK-LABEL: atan_test
Meador Inge193e0352012-11-13 04:16:17 +000086; CHECK: call float @atanf(float %f)
87}
88
Sanjay Patela92fa442014-10-22 15:29:23 +000089define double @atan_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +000090 %conv = fpext float %f to double
91 %call = call double @atan(double %conv)
92 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +000093; CHECK-LABEL: atan_test2
Meador Inge193e0352012-11-13 04:16:17 +000094; CHECK: call double @atan(double %conv)
95}
Sanjay Patela92fa442014-10-22 15:29:23 +000096define float @atanh_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +000097 %conv = fpext float %f to double
98 %call = call double @atanh(double %conv)
99 %conv1 = fptrunc double %call to float
100 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000101; CHECK-LABEL: atanh_test
Meador Inge193e0352012-11-13 04:16:17 +0000102; CHECK: call float @atanhf(float %f)
103}
104
Sanjay Patela92fa442014-10-22 15:29:23 +0000105define double @atanh_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000106 %conv = fpext float %f to double
107 %call = call double @atanh(double %conv)
108 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +0000109; CHECK-LABEL: atanh_test2
Meador Inge193e0352012-11-13 04:16:17 +0000110; CHECK: call double @atanh(double %conv)
111}
Sanjay Patela92fa442014-10-22 15:29:23 +0000112define float @cbrt_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000113 %conv = fpext float %f to double
114 %call = call double @cbrt(double %conv)
115 %conv1 = fptrunc double %call to float
116 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000117; CHECK-LABEL: cbrt_test
Meador Inge193e0352012-11-13 04:16:17 +0000118; CHECK: call float @cbrtf(float %f)
119}
120
Sanjay Patela92fa442014-10-22 15:29:23 +0000121define double @cbrt_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000122 %conv = fpext float %f to double
123 %call = call double @cbrt(double %conv)
124 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +0000125; CHECK-LABEL: cbrt_test2
Meador Inge193e0352012-11-13 04:16:17 +0000126; CHECK: call double @cbrt(double %conv)
127}
Sanjay Patela92fa442014-10-22 15:29:23 +0000128define float @exp_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000129 %conv = fpext float %f to double
130 %call = call double @exp(double %conv)
131 %conv1 = fptrunc double %call to float
132 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000133; CHECK-LABEL: exp_test
Meador Inge193e0352012-11-13 04:16:17 +0000134; CHECK: call float @expf(float %f)
135}
136
Sanjay Patela92fa442014-10-22 15:29:23 +0000137define double @exp_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000138 %conv = fpext float %f to double
139 %call = call double @exp(double %conv)
140 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +0000141; CHECK-LABEL: exp_test2
Meador Inge193e0352012-11-13 04:16:17 +0000142; CHECK: call double @exp(double %conv)
143}
Sanjay Patela92fa442014-10-22 15:29:23 +0000144define float @expm1_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000145 %conv = fpext float %f to double
146 %call = call double @expm1(double %conv)
147 %conv1 = fptrunc double %call to float
148 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000149; CHECK-LABEL: expm1_test
Meador Inge193e0352012-11-13 04:16:17 +0000150; CHECK: call float @expm1f(float %f)
151}
152
Sanjay Patela92fa442014-10-22 15:29:23 +0000153define double @expm1_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000154 %conv = fpext float %f to double
155 %call = call double @expm1(double %conv)
156 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +0000157; CHECK-LABEL: expm1_test2
Meador Inge193e0352012-11-13 04:16:17 +0000158; CHECK: call double @expm1(double %conv)
159}
Sanjay Patela92fa442014-10-22 15:29:23 +0000160define float @exp10_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000161 %conv = fpext float %f to double
162 %call = call double @exp10(double %conv)
163 %conv1 = fptrunc double %call to float
164 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000165; CHECK-LABEL: exp10_test
Chandler Carruthf5689f82013-12-28 02:40:19 +0000166; CHECK: call double @exp10(double %conv)
Meador Inge193e0352012-11-13 04:16:17 +0000167}
168
Sanjay Patela92fa442014-10-22 15:29:23 +0000169define double @exp10_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000170 %conv = fpext float %f to double
171 %call = call double @exp10(double %conv)
172 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +0000173; CHECK-LABEL: exp10_test2
Meador Inge193e0352012-11-13 04:16:17 +0000174; CHECK: call double @exp10(double %conv)
175}
Sanjay Patela92fa442014-10-22 15:29:23 +0000176define float @log_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000177 %conv = fpext float %f to double
178 %call = call double @log(double %conv)
179 %conv1 = fptrunc double %call to float
180 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000181; CHECK-LABEL: log_test
Meador Inge193e0352012-11-13 04:16:17 +0000182; CHECK: call float @logf(float %f)
183}
184
Sanjay Patela92fa442014-10-22 15:29:23 +0000185define double @log_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000186 %conv = fpext float %f to double
187 %call = call double @log(double %conv)
188 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +0000189; CHECK-LABEL: log_test2
Meador Inge193e0352012-11-13 04:16:17 +0000190; CHECK: call double @log(double %conv)
191}
Sanjay Patela92fa442014-10-22 15:29:23 +0000192define float @log10_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000193 %conv = fpext float %f to double
194 %call = call double @log10(double %conv)
195 %conv1 = fptrunc double %call to float
196 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000197; CHECK-LABEL: log10_test
Meador Inge193e0352012-11-13 04:16:17 +0000198; CHECK: call float @log10f(float %f)
199}
200
Sanjay Patela92fa442014-10-22 15:29:23 +0000201define double @log10_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000202 %conv = fpext float %f to double
203 %call = call double @log10(double %conv)
204 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +0000205; CHECK-LABEL: log10_test2
Meador Inge193e0352012-11-13 04:16:17 +0000206; CHECK: call double @log10(double %conv)
207}
Sanjay Patela92fa442014-10-22 15:29:23 +0000208define float @log1p_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000209 %conv = fpext float %f to double
210 %call = call double @log1p(double %conv)
211 %conv1 = fptrunc double %call to float
212 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000213; CHECK-LABEL: log1p_test
Meador Inge193e0352012-11-13 04:16:17 +0000214; CHECK: call float @log1pf(float %f)
215}
216
Sanjay Patela92fa442014-10-22 15:29:23 +0000217define double @log1p_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000218 %conv = fpext float %f to double
219 %call = call double @log1p(double %conv)
220 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +0000221; CHECK-LABEL: log1p_test2
Meador Inge193e0352012-11-13 04:16:17 +0000222; CHECK: call double @log1p(double %conv)
223}
Sanjay Patela92fa442014-10-22 15:29:23 +0000224define float @log2_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000225 %conv = fpext float %f to double
226 %call = call double @log2(double %conv)
227 %conv1 = fptrunc double %call to float
228 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000229; CHECK-LABEL: log2_test
Meador Inge193e0352012-11-13 04:16:17 +0000230; CHECK: call float @log2f(float %f)
231}
232
Sanjay Patela92fa442014-10-22 15:29:23 +0000233define double @log2_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000234 %conv = fpext float %f to double
235 %call = call double @log2(double %conv)
236 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +0000237; CHECK-LABEL: log2_test2
Meador Inge193e0352012-11-13 04:16:17 +0000238; CHECK: call double @log2(double %conv)
239}
Sanjay Patela92fa442014-10-22 15:29:23 +0000240define float @logb_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000241 %conv = fpext float %f to double
242 %call = call double @logb(double %conv)
243 %conv1 = fptrunc double %call to float
244 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000245; CHECK-LABEL: logb_test
Meador Inge193e0352012-11-13 04:16:17 +0000246; CHECK: call float @logbf(float %f)
247}
248
Sanjay Patela92fa442014-10-22 15:29:23 +0000249define double @logb_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000250 %conv = fpext float %f to double
251 %call = call double @logb(double %conv)
252 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +0000253; CHECK-LABEL: logb_test2
Meador Inge193e0352012-11-13 04:16:17 +0000254; CHECK: call double @logb(double %conv)
255}
Sanjay Patela92fa442014-10-22 15:29:23 +0000256define float @sin_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000257 %conv = fpext float %f to double
258 %call = call double @sin(double %conv)
259 %conv1 = fptrunc double %call to float
260 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000261; CHECK-LABEL: sin_test
Meador Inge193e0352012-11-13 04:16:17 +0000262; CHECK: call float @sinf(float %f)
263}
264
Sanjay Patela92fa442014-10-22 15:29:23 +0000265define double @sin_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000266 %conv = fpext float %f to double
267 %call = call double @sin(double %conv)
268 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +0000269; CHECK-LABEL: sin_test2
Meador Inge193e0352012-11-13 04:16:17 +0000270; CHECK: call double @sin(double %conv)
271}
Hal Finkel12100bf2013-11-16 21:29:08 +0000272
Sanjay Patela92fa442014-10-22 15:29:23 +0000273define float @sqrt_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000274 %conv = fpext float %f to double
275 %call = call double @sqrt(double %conv)
276 %conv1 = fptrunc double %call to float
277 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000278; CHECK-LABEL: sqrt_test
Meador Inge193e0352012-11-13 04:16:17 +0000279; CHECK: call float @sqrtf(float %f)
280}
281
Sanjay Patel848309d2014-10-23 21:52:45 +0000282define double @sqrt_test2(float %f) {
283 %conv = fpext float %f to double
284 %call = call double @sqrt(double %conv)
285 ret double %call
286; CHECK-LABEL: sqrt_test2
287; CHECK: call double @sqrt(double %conv)
288}
289
Sanjay Patela92fa442014-10-22 15:29:23 +0000290define float @sqrt_int_test(float %f) {
Hal Finkel12100bf2013-11-16 21:29:08 +0000291 %conv = fpext float %f to double
292 %call = call double @llvm.sqrt.f64(double %conv)
293 %conv1 = fptrunc double %call to float
294 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000295; CHECK-LABEL: sqrt_int_test
Hal Finkel12100bf2013-11-16 21:29:08 +0000296; CHECK: call float @llvm.sqrt.f32(float %f)
297}
298
Sanjay Patel848309d2014-10-23 21:52:45 +0000299define double @sqrt_int_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000300 %conv = fpext float %f to double
Sanjay Patel848309d2014-10-23 21:52:45 +0000301 %call = call double @llvm.sqrt.f64(double %conv)
Meador Inge193e0352012-11-13 04:16:17 +0000302 ret double %call
Sanjay Patel848309d2014-10-23 21:52:45 +0000303; CHECK-LABEL: sqrt_int_test2
304; CHECK: call double @llvm.sqrt.f64(double %conv)
Meador Inge193e0352012-11-13 04:16:17 +0000305}
Sanjay Patel848309d2014-10-23 21:52:45 +0000306
Sanjay Patela92fa442014-10-22 15:29:23 +0000307define float @tan_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000308 %conv = fpext float %f to double
309 %call = call double @tan(double %conv)
310 %conv1 = fptrunc double %call to float
311 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000312; CHECK-LABEL: tan_test
Meador Inge193e0352012-11-13 04:16:17 +0000313; CHECK: call float @tanf(float %f)
314}
315
Sanjay Patela92fa442014-10-22 15:29:23 +0000316define double @tan_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000317 %conv = fpext float %f to double
318 %call = call double @tan(double %conv)
319 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +0000320; CHECK-LABEL: tan_test2
Meador Inge193e0352012-11-13 04:16:17 +0000321; CHECK: call double @tan(double %conv)
322}
Sanjay Patela92fa442014-10-22 15:29:23 +0000323define float @tanh_test(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000324 %conv = fpext float %f to double
325 %call = call double @tanh(double %conv)
326 %conv1 = fptrunc double %call to float
327 ret float %conv1
Sanjay Patela92fa442014-10-22 15:29:23 +0000328; CHECK-LABEL: tanh_test
Meador Inge193e0352012-11-13 04:16:17 +0000329; CHECK: call float @tanhf(float %f)
330}
331
Sanjay Patela92fa442014-10-22 15:29:23 +0000332define double @tanh_test2(float %f) {
Meador Inge193e0352012-11-13 04:16:17 +0000333 %conv = fpext float %f to double
334 %call = call double @tanh(double %conv)
335 ret double %call
Sanjay Patela92fa442014-10-22 15:29:23 +0000336; CHECK-LABEL: tanh_test2
Meador Inge193e0352012-11-13 04:16:17 +0000337; CHECK: call double @tanh(double %conv)
338}
339
Sanjay Patela92fa442014-10-22 15:29:23 +0000340declare double @tanh(double) #1
341declare double @tan(double) #1
Sanjay Patel848309d2014-10-23 21:52:45 +0000342
343; sqrt is a special case: the shrinking optimization
344; is valid even without unsafe-fp-math.
345declare double @sqrt(double)
346declare double @llvm.sqrt.f64(double)
347
Sanjay Patela92fa442014-10-22 15:29:23 +0000348declare double @sin(double) #1
349declare double @log2(double) #1
350declare double @log1p(double) #1
351declare double @log10(double) #1
352declare double @log(double) #1
353declare double @logb(double) #1
354declare double @exp10(double) #1
355declare double @expm1(double) #1
356declare double @exp(double) #1
357declare double @cbrt(double) #1
358declare double @atanh(double) #1
359declare double @atan(double) #1
360declare double @acos(double) #1
361declare double @acosh(double) #1
362declare double @asin(double) #1
363declare double @asinh(double) #1
Hal Finkel12100bf2013-11-16 21:29:08 +0000364
Sanjay Patela92fa442014-10-22 15:29:23 +0000365attributes #1 = { "unsafe-fp-math"="true" }
Hal Finkel12100bf2013-11-16 21:29:08 +0000366