1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define float @powf_expf(float %x, float %y) {
5 ; CHECK-LABEL: @powf_expf(
6 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast float [[X:%.*]], [[Y:%.*]]
7 ; CHECK-NEXT: [[EXP:%.*]] = call fast float @llvm.exp.f32(float [[MUL]])
8 ; CHECK-NEXT: ret float [[EXP]]
10 %call = call fast float @expf(float %x) nounwind readnone
11 %pow = call fast float @llvm.pow.f32(float %call, float %y)
15 define float @powf_expf_libcall(float %x, float %y) {
16 ; CHECK-LABEL: @powf_expf_libcall(
17 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast float [[X:%.*]], [[Y:%.*]]
18 ; CHECK-NEXT: [[EXPF:%.*]] = call fast float @expf(float [[MUL]])
19 ; CHECK-NEXT: ret float [[EXPF]]
21 %call = call fast float @expf(float %x)
22 %pow = call fast float @powf(float %call, float %y)
26 define double @pow_exp(double %x, double %y) {
27 ; CHECK-LABEL: @pow_exp(
28 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast double [[X:%.*]], [[Y:%.*]]
29 ; CHECK-NEXT: [[EXP:%.*]] = call fast double @llvm.exp.f64(double [[MUL]])
30 ; CHECK-NEXT: ret double [[EXP]]
32 %call = call fast double @exp(double %x) nounwind readnone
33 %pow = call fast double @llvm.pow.f64(double %call, double %y)
37 define double @pow_exp_not_intrinsic(double %x, double %y) {
38 ; CHECK-LABEL: @pow_exp_not_intrinsic(
39 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast double [[X:%.*]], [[Y:%.*]]
40 ; CHECK-NEXT: [[EXP:%.*]] = call fast double @llvm.exp.f64(double [[MUL]])
41 ; CHECK-NEXT: ret double [[EXP]]
43 %call = call fast double @exp(double %x) nounwind readnone
44 %pow = call fast double @pow(double %call, double %y) nounwind readnone
48 define fp128 @powl_expl(fp128 %x, fp128 %y) {
49 ; CHECK-LABEL: @powl_expl(
50 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast fp128 [[X:%.*]], [[Y:%.*]]
51 ; CHECK-NEXT: [[EXP:%.*]] = call fast fp128 @llvm.exp.f128(fp128 [[MUL]])
52 ; CHECK-NEXT: ret fp128 [[EXP]]
54 %call = call fast fp128 @expl(fp128 %x) nounwind readnone
55 %pow = call fast fp128 @llvm.pow.f128(fp128 %call, fp128 %y)
59 define fp128 @powl_expl_not_fast(fp128 %x, fp128 %y) {
60 ; CHECK-LABEL: @powl_expl_not_fast(
61 ; CHECK-NEXT: [[CALL:%.*]] = call fp128 @expl(fp128 [[X:%.*]])
62 ; CHECK-NEXT: [[POW:%.*]] = call fast fp128 @llvm.pow.f128(fp128 [[CALL]], fp128 [[Y:%.*]])
63 ; CHECK-NEXT: ret fp128 [[POW]]
65 %call = call fp128 @expl(fp128 %x)
66 %pow = call fast fp128 @llvm.pow.f128(fp128 %call, fp128 %y)
70 define float @powf_exp2f(float %x, float %y) {
71 ; CHECK-LABEL: @powf_exp2f(
72 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast float [[X:%.*]], [[Y:%.*]]
73 ; CHECK-NEXT: [[EXP2:%.*]] = call fast float @llvm.exp2.f32(float [[MUL]])
74 ; CHECK-NEXT: ret float [[EXP2]]
76 %call = call fast float @exp2f(float %x) nounwind readnone
77 %pow = call fast float @llvm.pow.f32(float %call, float %y)
81 define float @powf_exp2f_not_intrinsic(float %x, float %y) {
82 ; CHECK-LABEL: @powf_exp2f_not_intrinsic(
83 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast float [[X:%.*]], [[Y:%.*]]
84 ; CHECK-NEXT: [[EXP2:%.*]] = call fast float @llvm.exp2.f32(float [[MUL]])
85 ; CHECK-NEXT: ret float [[EXP2]]
87 %call = call fast float @exp2f(float %x) nounwind readnone
88 %pow = call fast float @powf(float %call, float %y) nounwind readnone
92 define double @pow_exp2(double %x, double %y) {
93 ; CHECK-LABEL: @pow_exp2(
94 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast double [[X:%.*]], [[Y:%.*]]
95 ; CHECK-NEXT: [[EXP2:%.*]] = call fast double @llvm.exp2.f64(double [[MUL]])
96 ; CHECK-NEXT: ret double [[EXP2]]
98 %call = call fast double @exp2(double %x) nounwind readnone
99 %pow = call fast double @llvm.pow.f64(double %call, double %y)
103 define double @pow_exp2_libcall(double %x, double %y) {
104 ; CHECK-LABEL: @pow_exp2_libcall(
105 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast double [[X:%.*]], [[Y:%.*]]
106 ; CHECK-NEXT: [[EXP2:%.*]] = call fast double @exp2(double [[MUL]])
107 ; CHECK-NEXT: ret double [[EXP2]]
109 %call = call fast double @exp2(double %x)
110 %pow = call fast double @pow(double %call, double %y)
114 define fp128 @powl_exp2l(fp128 %x, fp128 %y) {
115 ; CHECK-LABEL: @powl_exp2l(
116 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast fp128 [[X:%.*]], [[Y:%.*]]
117 ; CHECK-NEXT: [[EXP2:%.*]] = call fast fp128 @llvm.exp2.f128(fp128 [[MUL]])
118 ; CHECK-NEXT: ret fp128 [[EXP2]]
120 %call = call fast fp128 @exp2l(fp128 %x) nounwind readnone
121 %pow = call fast fp128 @llvm.pow.f128(fp128 %call, fp128 %y)
125 define fp128 @powl_exp2l_not_fast(fp128 %x, fp128 %y) {
126 ; CHECK-LABEL: @powl_exp2l_not_fast(
127 ; CHECK-NEXT: [[CALL:%.*]] = call fp128 @exp2l(fp128 [[X:%.*]])
128 ; CHECK-NEXT: [[POW:%.*]] = call fast fp128 @llvm.pow.f128(fp128 [[CALL]], fp128 [[Y:%.*]])
129 ; CHECK-NEXT: ret fp128 [[POW]]
131 %call = call fp128 @exp2l(fp128 %x)
132 %pow = call fast fp128 @llvm.pow.f128(fp128 %call, fp128 %y)
136 ; TODO: exp10() is not widely enabled by many targets yet.
138 define float @powf_exp10f(float %x, float %y) {
139 ; CHECK-LABEL: @powf_exp10f(
140 ; CHECK-NEXT: [[CALL:%.*]] = call fast float @exp10f(float [[X:%.*]]) #1
141 ; CHECK-NEXT: [[POW:%.*]] = call fast float @llvm.pow.f32(float [[CALL]], float [[Y:%.*]])
142 ; CHECK-NEXT: ret float [[POW]]
144 %call = call fast float @exp10f(float %x) nounwind readnone
145 %pow = call fast float @llvm.pow.f32(float %call, float %y)
149 define double @pow_exp10(double %x, double %y) {
150 ; CHECK-LABEL: @pow_exp10(
151 ; CHECK-NEXT: [[CALL:%.*]] = call fast double @exp10(double [[X:%.*]]) #1
152 ; CHECK-NEXT: [[POW:%.*]] = call fast double @llvm.pow.f64(double [[CALL]], double [[Y:%.*]])
153 ; CHECK-NEXT: ret double [[POW]]
155 %call = call fast double @exp10(double %x) nounwind readnone
156 %pow = call fast double @llvm.pow.f64(double %call, double %y)
160 define fp128 @pow_exp10l(fp128 %x, fp128 %y) {
161 ; CHECK-LABEL: @pow_exp10l(
162 ; CHECK-NEXT: [[CALL:%.*]] = call fast fp128 @exp10l(fp128 [[X:%.*]]) #1
163 ; CHECK-NEXT: [[POW:%.*]] = call fast fp128 @llvm.pow.f128(fp128 [[CALL]], fp128 [[Y:%.*]])
164 ; CHECK-NEXT: ret fp128 [[POW]]
166 %call = call fast fp128 @exp10l(fp128 %x) nounwind readnone
167 %pow = call fast fp128 @llvm.pow.f128(fp128 %call, fp128 %y)
171 define float @reuse_fast(float %x, float %y, float * %p) {
172 ; CHECK-LABEL: @reuse_fast(
173 ; CHECK-NEXT: [[EXP:%.*]] = call fast float @expf(float [[X:%.*]])
174 ; CHECK-NEXT: [[POW:%.*]] = call fast float @powf(float [[EXP]], float [[Y:%.*]])
175 ; CHECK-NEXT: store float [[EXP]], float* [[P:%.*]], align 4
176 ; CHECK-NEXT: ret float [[POW]]
178 %exp = call fast float @expf(float %x)
179 %pow = call fast float @powf(float %exp, float %y)
180 store float %exp, float *%p, align 4
184 define fp128 @reuse_libcall(fp128 %x, fp128 %y, fp128 * %p) {
185 ; CHECK-LABEL: @reuse_libcall(
186 ; CHECK-NEXT: [[EXP:%.*]] = call fp128 @expl(fp128 [[X:%.*]])
187 ; CHECK-NEXT: [[POW:%.*]] = call fp128 @powl(fp128 [[EXP]], fp128 [[Y:%.*]])
188 ; CHECK-NEXT: store fp128 [[EXP]], fp128* [[P:%.*]], align 16
189 ; CHECK-NEXT: ret fp128 [[POW]]
191 %exp = call fp128 @expl(fp128 %x)
192 %pow = call fp128 @powl(fp128 %exp, fp128 %y)
193 store fp128 %exp, fp128 *%p, align 16
197 define double @function_pointer(double ()* %fptr, double %p1) {
198 ; CHECK-LABEL: @function_pointer(
199 ; CHECK-NEXT: [[CALL1:%.*]] = call fast double [[FPTR:%.*]]()
200 ; CHECK-NEXT: [[POW:%.*]] = call fast double @llvm.pow.f64(double [[CALL1]], double [[P1:%.*]])
201 ; CHECK-NEXT: ret double [[POW]]
203 %call1 = call fast double %fptr()
204 %pow = call fast double @llvm.pow.f64(double %call1, double %p1)
208 ; pow(C,x) -> exp2(log2(C)*x)
210 declare void @use_d(double)
211 declare void @use_f(float)
213 define double @pow_ok_base(double %e) {
214 ; CHECK-LABEL: @pow_ok_base(
215 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn double [[E:%.*]], 0xBFE0776228967D13
216 ; CHECK-NEXT: [[EXP2:%.*]] = call nnan ninf afn double @exp2(double [[MUL]])
217 ; CHECK-NEXT: ret double [[EXP2]]
219 %call = tail call afn nnan ninf double @pow(double 0x3FE6666666666666, double %e)
223 define double @pow_ok_base_fast(double %e) {
224 ; CHECK-LABEL: @pow_ok_base_fast(
225 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast double [[E:%.*]], 0xBFE0776228967D13
226 ; CHECK-NEXT: [[EXP2:%.*]] = call fast double @exp2(double [[MUL]])
227 ; CHECK-NEXT: ret double [[EXP2]]
229 %call = tail call fast double @pow(double 0x3FE6666666666666, double %e)
233 define double @pow_ok_base2(double %e) {
234 ; CHECK-LABEL: @pow_ok_base2(
235 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn double [[E:%.*]], 0x4010952C788751AC
236 ; CHECK-NEXT: [[EXP2:%.*]] = call nnan ninf afn double @exp2(double [[MUL]])
237 ; CHECK-NEXT: ret double [[EXP2]]
239 %call = tail call afn nnan ninf double @pow(double 1.770000e+01, double %e)
243 define double @pow_ok_base3(double %e) {
244 ; CHECK-LABEL: @pow_ok_base3(
245 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn double [[E:%.*]], 0x400AB0B5584886CD
246 ; CHECK-NEXT: [[EXP2:%.*]] = call nnan ninf afn double @exp2(double [[MUL]])
247 ; CHECK-NEXT: ret double [[EXP2]]
249 %call = tail call afn nnan ninf double @pow(double 1.010000e+01, double %e)
253 define double @pow_ok_ten_base(double %e) {
254 ; CHECK-LABEL: @pow_ok_ten_base(
255 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn double [[E:%.*]], 0x400A934F0979A371
256 ; CHECK-NEXT: [[EXP2:%.*]] = call nnan ninf afn double @exp2(double [[MUL]])
257 ; CHECK-NEXT: ret double [[EXP2]]
259 %call = tail call afn nnan ninf double @pow(double 1.000000e+01, double %e)
263 define float @powf_ok_base(float %e) {
264 ; CHECK-LABEL: @powf_ok_base(
265 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn float [[E:%.*]], 0xBFE0776240000000
266 ; CHECK-NEXT: [[EXP2F:%.*]] = call nnan ninf afn float @exp2f(float [[MUL]])
267 ; CHECK-NEXT: ret float [[EXP2F]]
269 %call = tail call afn nnan ninf float @powf(float 0x3FE6666660000000, float %e)
273 define float @powf_ok_base2(float %e) {
274 ; CHECK-LABEL: @powf_ok_base2(
275 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn float [[E:%.*]], 0x4010952C80000000
276 ; CHECK-NEXT: [[EXP2F:%.*]] = call nnan ninf afn float @exp2f(float [[MUL]])
277 ; CHECK-NEXT: ret float [[EXP2F]]
279 %call = tail call afn nnan ninf float @powf(float 0x4031B33340000000, float %e)
283 define float @powf_ok_base3(float %e) {
284 ; CHECK-LABEL: @powf_ok_base3(
285 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn float [[E:%.*]], 0x400AB0B560000000
286 ; CHECK-NEXT: [[EXP2F:%.*]] = call nnan ninf afn float @exp2f(float [[MUL]])
287 ; CHECK-NEXT: ret float [[EXP2F]]
289 %call = tail call afn nnan ninf float @powf(float 0x4024333340000000, float %e)
293 define float @powf_ok_ten_base(float %e) {
294 ; CHECK-LABEL: @powf_ok_ten_base(
295 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn float [[E:%.*]], 0x400A934F00000000
296 ; CHECK-NEXT: [[EXP2F:%.*]] = call nnan ninf afn float @exp2f(float [[MUL]])
297 ; CHECK-NEXT: ret float [[EXP2F]]
299 %call = tail call afn nnan ninf float @powf(float 1.000000e+01, float %e)
305 define double @pow_zero_base(double %e) {
306 ; CHECK-LABEL: @pow_zero_base(
307 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double 0.000000e+00, double [[E:%.*]])
308 ; CHECK-NEXT: ret double [[CALL]]
310 %call = tail call afn nnan ninf double @pow(double 0.000000e+00, double %e)
314 define double @pow_zero_base2(double %e) {
315 ; CHECK-LABEL: @pow_zero_base2(
316 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double -0.000000e+00, double [[E:%.*]])
317 ; CHECK-NEXT: ret double [[CALL]]
319 %call = tail call afn nnan ninf double @pow(double -0.000000e+00, double %e)
323 define double @pow_inf_base(double %e) {
324 ; CHECK-LABEL: @pow_inf_base(
325 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double 0x7FF0000000000000, double [[E:%.*]])
326 ; CHECK-NEXT: ret double [[CALL]]
328 %call = tail call afn nnan ninf double @pow(double 0x7FF0000000000000, double %e)
332 define double @pow_nan_base(double %e) {
333 ; CHECK-LABEL: @pow_nan_base(
334 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double 0x7FF8000000000000, double [[E:%.*]])
335 ; CHECK-NEXT: ret double [[CALL]]
337 %call = tail call afn nnan ninf double @pow(double 0x7FF8000000000000, double %e)
341 define double @pow_negative_base(double %e) {
342 ; CHECK-LABEL: @pow_negative_base(
343 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double -4.000000e+00, double [[E:%.*]])
344 ; CHECK-NEXT: ret double [[CALL]]
346 %call = tail call afn nnan ninf double @pow(double -4.000000e+00, double %e)
350 define double @pow_multiuse(double %e) {
351 ; CHECK-LABEL: @pow_multiuse(
352 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double 5.000000e+00, double [[E:%.*]])
353 ; CHECK-NEXT: tail call void @use_d(double [[CALL]])
354 ; CHECK-NEXT: ret double [[CALL]]
356 %call = tail call afn nnan ninf double @pow(double 5.000000e+00, double %e)
357 tail call void @use_d(double %call)
361 define double @pow_ok_base_no_afn(double %e) {
362 ; CHECK-LABEL: @pow_ok_base_no_afn(
363 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf double @pow(double 0x3FE6666666666666, double [[E:%.*]])
364 ; CHECK-NEXT: ret double [[CALL]]
366 %call = tail call nnan ninf double @pow(double 0x3FE6666666666666, double %e)
370 define double @pow_ok_base_no_nnan(double %e) {
371 ; CHECK-LABEL: @pow_ok_base_no_nnan(
372 ; CHECK-NEXT: [[CALL:%.*]] = tail call ninf afn double @pow(double 0x3FE6666666666666, double [[E:%.*]])
373 ; CHECK-NEXT: ret double [[CALL]]
375 %call = tail call afn ninf double @pow(double 0x3FE6666666666666, double %e)
379 define double @pow_ok_base_no_ninf(double %e) {
380 ; CHECK-LABEL: @pow_ok_base_no_ninf(
381 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan afn double @pow(double 0x3FE6666666666666, double [[E:%.*]])
382 ; CHECK-NEXT: ret double [[CALL]]
384 %call = tail call afn nnan double @pow(double 0x3FE6666666666666, double %e)
388 define float @powf_zero_base(float %e) {
389 ; CHECK-LABEL: @powf_zero_base(
390 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float 0.000000e+00, float [[E:%.*]])
391 ; CHECK-NEXT: ret float [[CALL]]
393 %call = tail call afn nnan ninf float @powf(float 0.000000e+00, float %e)
397 define float @powf_zero_base2(float %e) {
398 ; CHECK-LABEL: @powf_zero_base2(
399 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float -0.000000e+00, float [[E:%.*]])
400 ; CHECK-NEXT: ret float [[CALL]]
402 %call = tail call afn nnan ninf float @powf(float -0.000000e+00, float %e)
406 define float @powf_inf_base(float %e) {
407 ; CHECK-LABEL: @powf_inf_base(
408 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float 0x7FF0000000000000, float [[E:%.*]])
409 ; CHECK-NEXT: ret float [[CALL]]
411 %call = tail call afn nnan ninf float @powf(float 0x7FF0000000000000, float %e)
415 define float @powf_nan_base(float %e) {
416 ; CHECK-LABEL: @powf_nan_base(
417 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float 0x7FF8000000000000, float [[E:%.*]])
418 ; CHECK-NEXT: ret float [[CALL]]
420 %call = tail call afn nnan ninf float @powf(float 0x7FF8000000000000, float %e)
424 define float @powf_negative_base(float %e) {
425 ; CHECK-LABEL: @powf_negative_base(
426 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float -4.000000e+00, float [[E:%.*]])
427 ; CHECK-NEXT: ret float [[CALL]]
429 %call = tail call afn nnan ninf float @powf(float -4.000000e+00, float %e)
433 define float @powf_multiuse(float %e) {
434 ; CHECK-LABEL: @powf_multiuse(
435 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float 5.000000e+00, float [[E:%.*]])
436 ; CHECK-NEXT: tail call void @use_f(float [[CALL]])
437 ; CHECK-NEXT: ret float [[CALL]]
439 %call = tail call afn nnan ninf float @powf(float 5.000000e+00, float %e)
440 tail call void @use_f(float %call)
444 define float @powf_ok_base_no_afn(float %e) {
445 ; CHECK-LABEL: @powf_ok_base_no_afn(
446 ; CHECK-NEXT: [[CALL:%.*]] = tail call float @powf(float 0x3FE6666660000000, float [[E:%.*]])
447 ; CHECK-NEXT: ret float [[CALL]]
449 %call = tail call float @powf(float 0x3FE6666660000000, float %e)
453 define fp128 @powl_long_dbl_no_fold(fp128 %e) {
454 ; CHECK-LABEL: @powl_long_dbl_no_fold(
455 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn fp128 @powl(fp128 0xL00000000000000005001000000000000, fp128 [[E:%.*]])
456 ; CHECK-NEXT: ret fp128 [[CALL]]
458 %call = tail call afn nnan ninf fp128 @powl(fp128 0xL00000000000000005001000000000000, fp128 %e)
462 declare float @expf(float)
463 declare double @exp(double)
464 declare fp128 @expl(fp128)
465 declare float @exp2f(float)
466 declare double @exp2(double)
467 declare fp128 @exp2l(fp128)
468 declare float @exp10f(float)
469 declare double @exp10(double)
470 declare fp128 @exp10l(fp128)
471 declare float @powf(float, float)
472 declare double @pow(double, double)
473 declare fp128 @powl(fp128, fp128)
474 declare float @llvm.pow.f32(float, float)
475 declare double @llvm.pow.f64(double, double)
476 declare fp128 @llvm.pow.f128(fp128, fp128)