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 ; Do not change 0xBFE0776{{.*}} to the exact constant, see PR42740
216 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn double [[E:%.*]], 0xBFE0776{{.*}}
217 ; CHECK-NEXT: [[EXP2:%.*]] = call nnan ninf afn double @exp2(double [[MUL]])
218 ; CHECK-NEXT: ret double [[EXP2]]
220 %call = tail call afn nnan ninf double @pow(double 0x3FE6666666666666, double %e)
224 define double @pow_ok_base_fast(double %e) {
225 ; CHECK-LABEL: @pow_ok_base_fast(
226 ; CHECK-NEXT: [[MUL:%.*]] = fmul fast double [[E:%.*]], 0xBFE0776{{.*}}
227 ; CHECK-NEXT: [[EXP2:%.*]] = call fast double @exp2(double [[MUL]])
228 ; CHECK-NEXT: ret double [[EXP2]]
230 %call = tail call fast double @pow(double 0x3FE6666666666666, double %e)
234 define double @pow_ok_base2(double %e) {
235 ; CHECK-LABEL: @pow_ok_base2(
236 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn double [[E:%.*]], 0x4010952{{.*}}
237 ; CHECK-NEXT: [[EXP2:%.*]] = call nnan ninf afn double @exp2(double [[MUL]])
238 ; CHECK-NEXT: ret double [[EXP2]]
240 %call = tail call afn nnan ninf double @pow(double 1.770000e+01, double %e)
244 define double @pow_ok_base3(double %e) {
245 ; CHECK-LABEL: @pow_ok_base3(
246 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn double [[E:%.*]], 0x400AB0B5{{.*}}
247 ; CHECK-NEXT: [[EXP2:%.*]] = call nnan ninf afn double @exp2(double [[MUL]])
248 ; CHECK-NEXT: ret double [[EXP2]]
250 %call = tail call afn nnan ninf double @pow(double 1.010000e+01, double %e)
254 define double @pow_ok_ten_base(double %e) {
255 ; CHECK-LABEL: @pow_ok_ten_base(
256 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn double [[E:%.*]], 0x400A934F{{.*}}
257 ; CHECK-NEXT: [[EXP2:%.*]] = call nnan ninf afn double @exp2(double [[MUL]])
258 ; CHECK-NEXT: ret double [[EXP2]]
260 %call = tail call afn nnan ninf double @pow(double 1.000000e+01, double %e)
264 define float @powf_ok_base(float %e) {
265 ; CHECK-LABEL: @powf_ok_base(
266 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn float [[E:%.*]], 0xBFE07762{{.*}}
267 ; CHECK-NEXT: [[EXP2F:%.*]] = call nnan ninf afn float @exp2f(float [[MUL]])
268 ; CHECK-NEXT: ret float [[EXP2F]]
270 %call = tail call afn nnan ninf float @powf(float 0x3FE6666660000000, float %e)
274 define float @powf_ok_base2(float %e) {
275 ; CHECK-LABEL: @powf_ok_base2(
276 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn float [[E:%.*]], 0x4010952{{.*}}
277 ; CHECK-NEXT: [[EXP2F:%.*]] = call nnan ninf afn float @exp2f(float [[MUL]])
278 ; CHECK-NEXT: ret float [[EXP2F]]
280 %call = tail call afn nnan ninf float @powf(float 0x4031B33340000000, float %e)
284 define float @powf_ok_base3(float %e) {
285 ; CHECK-LABEL: @powf_ok_base3(
286 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn float [[E:%.*]], 0x400AB0B5{{.*}}
287 ; CHECK-NEXT: [[EXP2F:%.*]] = call nnan ninf afn float @exp2f(float [[MUL]])
288 ; CHECK-NEXT: ret float [[EXP2F]]
290 %call = tail call afn nnan ninf float @powf(float 0x4024333340000000, float %e)
294 define float @powf_ok_ten_base(float %e) {
295 ; CHECK-LABEL: @powf_ok_ten_base(
296 ; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn float [[E:%.*]], 0x400A934{{.*}}
297 ; CHECK-NEXT: [[EXP2F:%.*]] = call nnan ninf afn float @exp2f(float [[MUL]])
298 ; CHECK-NEXT: ret float [[EXP2F]]
300 %call = tail call afn nnan ninf float @powf(float 1.000000e+01, float %e)
306 define double @pow_zero_base(double %e) {
307 ; CHECK-LABEL: @pow_zero_base(
308 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double 0.000000e+00, double [[E:%.*]])
309 ; CHECK-NEXT: ret double [[CALL]]
311 %call = tail call afn nnan ninf double @pow(double 0.000000e+00, double %e)
315 define double @pow_zero_base2(double %e) {
316 ; CHECK-LABEL: @pow_zero_base2(
317 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double -0.000000e+00, double [[E:%.*]])
318 ; CHECK-NEXT: ret double [[CALL]]
320 %call = tail call afn nnan ninf double @pow(double -0.000000e+00, double %e)
324 define double @pow_inf_base(double %e) {
325 ; CHECK-LABEL: @pow_inf_base(
326 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double 0x7FF0000000000000, double [[E:%.*]])
327 ; CHECK-NEXT: ret double [[CALL]]
329 %call = tail call afn nnan ninf double @pow(double 0x7FF0000000000000, double %e)
333 define double @pow_nan_base(double %e) {
334 ; CHECK-LABEL: @pow_nan_base(
335 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double 0x7FF8000000000000, double [[E:%.*]])
336 ; CHECK-NEXT: ret double [[CALL]]
338 %call = tail call afn nnan ninf double @pow(double 0x7FF8000000000000, double %e)
342 define double @pow_negative_base(double %e) {
343 ; CHECK-LABEL: @pow_negative_base(
344 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double -4.000000e+00, double [[E:%.*]])
345 ; CHECK-NEXT: ret double [[CALL]]
347 %call = tail call afn nnan ninf double @pow(double -4.000000e+00, double %e)
351 define double @pow_multiuse(double %e) {
352 ; CHECK-LABEL: @pow_multiuse(
353 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double 5.000000e+00, double [[E:%.*]])
354 ; CHECK-NEXT: tail call void @use_d(double [[CALL]])
355 ; CHECK-NEXT: ret double [[CALL]]
357 %call = tail call afn nnan ninf double @pow(double 5.000000e+00, double %e)
358 tail call void @use_d(double %call)
362 define double @pow_ok_base_no_afn(double %e) {
363 ; CHECK-LABEL: @pow_ok_base_no_afn(
364 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf double @pow(double 0x3FE6666666666666, double [[E:%.*]])
365 ; CHECK-NEXT: ret double [[CALL]]
367 %call = tail call nnan ninf double @pow(double 0x3FE6666666666666, double %e)
371 define double @pow_ok_base_no_nnan(double %e) {
372 ; CHECK-LABEL: @pow_ok_base_no_nnan(
373 ; CHECK-NEXT: [[CALL:%.*]] = tail call ninf afn double @pow(double 0x3FE6666666666666, double [[E:%.*]])
374 ; CHECK-NEXT: ret double [[CALL]]
376 %call = tail call afn ninf double @pow(double 0x3FE6666666666666, double %e)
380 define double @pow_ok_base_no_ninf(double %e) {
381 ; CHECK-LABEL: @pow_ok_base_no_ninf(
382 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan afn double @pow(double 0x3FE6666666666666, double [[E:%.*]])
383 ; CHECK-NEXT: ret double [[CALL]]
385 %call = tail call afn nnan double @pow(double 0x3FE6666666666666, double %e)
389 define float @powf_zero_base(float %e) {
390 ; CHECK-LABEL: @powf_zero_base(
391 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float 0.000000e+00, float [[E:%.*]])
392 ; CHECK-NEXT: ret float [[CALL]]
394 %call = tail call afn nnan ninf float @powf(float 0.000000e+00, float %e)
398 define float @powf_zero_base2(float %e) {
399 ; CHECK-LABEL: @powf_zero_base2(
400 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float -0.000000e+00, float [[E:%.*]])
401 ; CHECK-NEXT: ret float [[CALL]]
403 %call = tail call afn nnan ninf float @powf(float -0.000000e+00, float %e)
407 define float @powf_inf_base(float %e) {
408 ; CHECK-LABEL: @powf_inf_base(
409 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float 0x7FF0000000000000, float [[E:%.*]])
410 ; CHECK-NEXT: ret float [[CALL]]
412 %call = tail call afn nnan ninf float @powf(float 0x7FF0000000000000, float %e)
416 define float @powf_nan_base(float %e) {
417 ; CHECK-LABEL: @powf_nan_base(
418 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float 0x7FF8000000000000, float [[E:%.*]])
419 ; CHECK-NEXT: ret float [[CALL]]
421 %call = tail call afn nnan ninf float @powf(float 0x7FF8000000000000, float %e)
425 define float @powf_negative_base(float %e) {
426 ; CHECK-LABEL: @powf_negative_base(
427 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float -4.000000e+00, float [[E:%.*]])
428 ; CHECK-NEXT: ret float [[CALL]]
430 %call = tail call afn nnan ninf float @powf(float -4.000000e+00, float %e)
434 define float @powf_multiuse(float %e) {
435 ; CHECK-LABEL: @powf_multiuse(
436 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float 5.000000e+00, float [[E:%.*]])
437 ; CHECK-NEXT: tail call void @use_f(float [[CALL]])
438 ; CHECK-NEXT: ret float [[CALL]]
440 %call = tail call afn nnan ninf float @powf(float 5.000000e+00, float %e)
441 tail call void @use_f(float %call)
445 define float @powf_ok_base_no_afn(float %e) {
446 ; CHECK-LABEL: @powf_ok_base_no_afn(
447 ; CHECK-NEXT: [[CALL:%.*]] = tail call float @powf(float 0x3FE6666660000000, float [[E:%.*]])
448 ; CHECK-NEXT: ret float [[CALL]]
450 %call = tail call float @powf(float 0x3FE6666660000000, float %e)
454 define fp128 @powl_long_dbl_no_fold(fp128 %e) {
455 ; CHECK-LABEL: @powl_long_dbl_no_fold(
456 ; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn fp128 @powl(fp128 0xL00000000000000005001000000000000, fp128 [[E:%.*]])
457 ; CHECK-NEXT: ret fp128 [[CALL]]
459 %call = tail call afn nnan ninf fp128 @powl(fp128 0xL00000000000000005001000000000000, fp128 %e)
463 declare float @expf(float)
464 declare double @exp(double)
465 declare fp128 @expl(fp128)
466 declare float @exp2f(float)
467 declare double @exp2(double)
468 declare fp128 @exp2l(fp128)
469 declare float @exp10f(float)
470 declare double @exp10(double)
471 declare fp128 @exp10l(fp128)
472 declare float @powf(float, float)
473 declare double @pow(double, double)
474 declare fp128 @powl(fp128, fp128)
475 declare float @llvm.pow.f32(float, float)
476 declare double @llvm.pow.f64(double, double)
477 declare fp128 @llvm.pow.f128(fp128, fp128)