diff --git a/llvm/test/Transforms/InstCombine/pow-1.ll b/llvm/test/Transforms/InstCombine/pow-1.ll index 1d01f23679e1..f1340a35a6b0 100644 --- a/llvm/test/Transforms/InstCombine/pow-1.ll +++ b/llvm/test/Transforms/InstCombine/pow-1.ll @@ -53,7 +53,7 @@ define <2 x double> @test_simplify2v(<2 x double> %x) { ret <2 x double> %retval } -; Check pow(2.0, x) -> exp2(x). +; Check pow(2.0 ** n, x) -> exp2(n * x). define float @test_simplify3(float %x) { ; ANY-LABEL: @test_simplify3( @@ -64,6 +64,16 @@ define float @test_simplify3(float %x) { ret float %retval } +; TODO: Should result in exp2(-2.0 * x). +define double @test_simplify3n(double %x) { +; ANY-LABEL: @test_simplify3n( +; ANY-NEXT: [[RETVAL:%.*]] = call double @pow(double 2.500000e-01, double [[X:%.*]]) +; ANY-NEXT: ret double [[RETVAL]] +; + %retval = call double @pow(double 0.25, double %x) + ret double %retval +} + define <2 x float> @test_simplify3v(<2 x float> %x) { ; ANY-LABEL: @test_simplify3v( ; ANY-NEXT: [[EXP2:%.*]] = call <2 x float> @llvm.exp2.v2f32(<2 x float> [[X:%.*]]) @@ -73,6 +83,16 @@ define <2 x float> @test_simplify3v(<2 x float> %x) { ret <2 x float> %retval } +; TODO: Should result in exp2(2.0 * x). +define <2 x double> @test_simplify3vn(<2 x double> %x) { +; ANY-LABEL: @test_simplify3vn( +; ANY-NEXT: [[RETVAL:%.*]] = call <2 x double> @llvm.pow.v2f64(<2 x double> , <2 x double> [[X:%.*]]) +; ANY-NEXT: ret <2 x double> [[RETVAL]] +; + %retval = call <2 x double> @llvm.pow.v2f64(<2 x double> , <2 x double> %x) + ret <2 x double> %retval +} + define double @test_simplify4(double %x) { ; ANY-LABEL: @test_simplify4( ; ANY-NEXT: [[EXP2:%.*]] = call double @llvm.exp2.f64(double [[X:%.*]]) @@ -82,6 +102,16 @@ define double @test_simplify4(double %x) { ret double %retval } +; TODO: Should result in exp2f(3.0 * x). +define float @test_simplify4n(float %x) { +; ANY-LABEL: @test_simplify4n( +; ANY-NEXT: [[RETVAL:%.*]] = call float @powf(float 8.000000e+00, float [[X:%.*]]) +; ANY-NEXT: ret float [[RETVAL]] +; + %retval = call float @powf(float 8.0, float %x) + ret float %retval +} + define <2 x double> @test_simplify4v(<2 x double> %x) { ; ANY-LABEL: @test_simplify4v( ; ANY-NEXT: [[EXP2:%.*]] = call <2 x double> @llvm.exp2.v2f64(<2 x double> [[X:%.*]]) @@ -91,6 +121,16 @@ define <2 x double> @test_simplify4v(<2 x double> %x) { ret <2 x double> %retval } +; TODO: Should result in exp2f(-x). +define <2 x float> @test_simplify4vn(<2 x float> %x) { +; ANY-LABEL: @test_simplify4vn( +; ANY-NEXT: [[RETVAL:%.*]] = call <2 x float> @llvm.pow.v2f32(<2 x float> , <2 x float> [[X:%.*]]) +; ANY-NEXT: ret <2 x float> [[RETVAL]] +; + %retval = call <2 x float> @llvm.pow.v2f32(<2 x float> , <2 x float> %x) + ret <2 x float> %retval +} + ; Check pow(x, 0.0) -> 1.0. define float @test_simplify5(float %x) { @@ -332,4 +372,3 @@ define double @test_simplify19(double %x) { } ; CHECK-EXP10: attributes [[NUW_RO]] = { nounwind readonly } - diff --git a/llvm/test/Transforms/InstCombine/pow-exp.ll b/llvm/test/Transforms/InstCombine/pow-exp.ll index 8714a7627854..781f592619c3 100644 --- a/llvm/test/Transforms/InstCombine/pow-exp.ll +++ b/llvm/test/Transforms/InstCombine/pow-exp.ll @@ -1,6 +1,19 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt < %s -instcombine -S | FileCheck %s +; TODO: Should result in expf(x * y). +define float @powf_expf(float %x, float %y) { +; CHECK-LABEL: @powf_expf( +; CHECK-NEXT: [[CALL:%.*]] = call fast float @expf(float [[X:%.*]]) #1 +; CHECK-NEXT: [[POW:%.*]] = call fast float @llvm.pow.f32(float [[CALL]], float [[Y:%.*]]) +; CHECK-NEXT: ret float [[POW]] +; + %call = call fast float @expf(float %x) nounwind readnone + %pow = call fast float @llvm.pow.f32(float %call, float %y) + ret float %pow +} + +; TODO: Should result in intrinsic call to exp(). define double @pow_exp(double %x, double %y) { ; CHECK-LABEL: @pow_exp( ; CHECK-NEXT: [[MUL:%.*]] = fmul fast double [[X:%.*]], [[Y:%.*]] @@ -12,6 +25,19 @@ define double @pow_exp(double %x, double %y) { ret double %pow } +; TODO: Should result in exp2f(x * y). +define float @powf_exp2f(float %x, float %y) { +; CHECK-LABEL: @powf_exp2f( +; CHECK-NEXT: [[CALL:%.*]] = call fast float @exp2f(float [[X:%.*]]) #1 +; CHECK-NEXT: [[POW:%.*]] = call fast float @llvm.pow.f32(float [[CALL]], float [[Y:%.*]]) +; CHECK-NEXT: ret float [[POW]] +; + %call = call fast float @exp2f(float %x) nounwind readnone + %pow = call fast float @llvm.pow.f32(float %call, float %y) + ret float %pow +} + +; TODO: Should result in intrinsic call to exp2(). define double @pow_exp2(double %x, double %y) { ; CHECK-LABEL: @pow_exp2( ; CHECK-NEXT: [[MUL:%.*]] = fmul fast double [[X:%.*]], [[Y:%.*]] @@ -23,6 +49,30 @@ define double @pow_exp2(double %x, double %y) { ret double %pow } +; TODO: exp10() is not widely enabled by many targets yet. + +define float @powf_exp10f(float %x, float %y) { +; CHECK-LABEL: @powf_exp10f( +; CHECK-NEXT: [[CALL:%.*]] = call fast float @exp10f(float [[X:%.*]]) #1 +; CHECK-NEXT: [[POW:%.*]] = call fast float @llvm.pow.f32(float [[CALL]], float [[Y:%.*]]) +; CHECK-NEXT: ret float [[POW]] +; + %call = call fast float @exp10f(float %x) nounwind readnone + %pow = call fast float @llvm.pow.f32(float %call, float %y) + ret float %pow +} + +define double @pow_exp10(double %x, double %y) { +; CHECK-LABEL: @pow_exp10( +; CHECK-NEXT: [[CALL:%.*]] = call fast double @exp10(double [[X:%.*]]) #1 +; CHECK-NEXT: [[POW:%.*]] = call fast double @llvm.pow.f64(double [[CALL]], double [[Y:%.*]]) +; CHECK-NEXT: ret double [[POW]] +; + %call = call fast double @exp10(double %x) nounwind readnone + %pow = call fast double @llvm.pow.f64(double %call, double %y) + ret double %pow +} + define double @pow_exp_not_fast(double %x, double %y) { ; CHECK-LABEL: @pow_exp_not_fast( ; CHECK-NEXT: [[CALL:%.*]] = call double @exp(double [[X:%.*]]) @@ -46,6 +96,10 @@ define double @function_pointer(double ()* %fptr, double %p1) { } declare double @exp(double) +declare float @expf(float) declare double @exp2(double) +declare float @exp2f(float) +declare double @exp10(double) +declare float @exp10f(float) declare double @llvm.pow.f64(double, double) - +declare float @llvm.pow.f32(float, float)