diff options
author | David Bolvansky <david.bolvansky@gmail.com> | 2019-07-11 10:55:04 +0000 |
---|---|---|
committer | David Bolvansky <david.bolvansky@gmail.com> | 2019-07-11 10:55:04 +0000 |
commit | e23be09e66d6860ec739b57d7821a7671d715a35 (patch) | |
tree | eef4da51bea1bb7b36c6667e8903b8616188aab5 /llvm | |
parent | 3b9994615f484d028ab476cf31bf6e62558364e8 (diff) | |
download | bcm5719-llvm-e23be09e66d6860ec739b57d7821a7671d715a35.tar.gz bcm5719-llvm-e23be09e66d6860ec739b57d7821a7671d715a35.zip |
[InstCombine] Reorder recently added/improved pow transformations
Changed cases are now faster with exp2.
llvm-svn: 365758
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 6 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/pow_fp_int.ll | 13 |
2 files changed, 11 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index b481d2b50a8..bc55e77c44f 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1471,6 +1471,9 @@ Value *LibCallSimplifier::optimizePow(CallInst *Pow, IRBuilder<> &B) { if (match(Base, m_FPOne())) return Base; + if (Value *Exp = replacePowWithExp(Pow, B)) + return Exp; + // powf(x, sitofp(e)) -> powi(x, e) // powf(x, uitofp(e)) -> powi(x, e) if (AllowApprox && (isa<SIToFPInst>(Expo) || isa<UIToFPInst>(Expo))) { @@ -1486,9 +1489,6 @@ Value *LibCallSimplifier::optimizePow(CallInst *Pow, IRBuilder<> &B) { return createPowWithIntegerExponent(Base, NewExpo, M, B); } - if (Value *Exp = replacePowWithExp(Pow, B)) - return Exp; - // Evaluate special cases related to the exponent. // pow(x, -1.0) -> 1.0 / x diff --git a/llvm/test/Transforms/InstCombine/pow_fp_int.ll b/llvm/test/Transforms/InstCombine/pow_fp_int.ll index f89353cd707..372a9e11c1e 100644 --- a/llvm/test/Transforms/InstCombine/pow_fp_int.ll +++ b/llvm/test/Transforms/InstCombine/pow_fp_int.ll @@ -51,8 +51,10 @@ define double @pow_uitofp_double_const_base_fast(i31 %x) { define double @pow_sitofp_double_const_base_power_of_2_fast(i32 %x) { ; CHECK-LABEL: @pow_sitofp_double_const_base_power_of_2_fast( -; CHECK-NEXT: [[TMP1:%.*]] = call afn float @llvm.powi.f32(float 1.600000e+01, i32 [[X:%.*]]) -; CHECK-NEXT: [[RES:%.*]] = fpext float [[TMP1]] to double +; CHECK-NEXT: [[SUBFP:%.*]] = sitofp i32 [[X:%.*]] to float +; CHECK-NEXT: [[MUL:%.*]] = fmul afn float [[SUBFP]], 4.000000e+00 +; CHECK-NEXT: [[EXP2:%.*]] = call afn float @llvm.exp2.f32(float [[MUL]]) +; CHECK-NEXT: [[RES:%.*]] = fpext float [[EXP2]] to double ; CHECK-NEXT: ret double [[RES]] ; %subfp = sitofp i32 %x to float @@ -63,9 +65,10 @@ define double @pow_sitofp_double_const_base_power_of_2_fast(i32 %x) { define double @pow_uitofp_const_base_power_of_2_fast(i31 %x) { ; CHECK-LABEL: @pow_uitofp_const_base_power_of_2_fast( -; CHECK-NEXT: [[TMP1:%.*]] = zext i31 [[X:%.*]] to i32 -; CHECK-NEXT: [[TMP2:%.*]] = call afn float @llvm.powi.f32(float 1.600000e+01, i32 [[TMP1]]) -; CHECK-NEXT: [[RES:%.*]] = fpext float [[TMP2]] to double +; CHECK-NEXT: [[SUBFP:%.*]] = uitofp i31 [[X:%.*]] to float +; CHECK-NEXT: [[MUL:%.*]] = fmul afn float [[SUBFP]], 4.000000e+00 +; CHECK-NEXT: [[EXP2:%.*]] = call afn float @llvm.exp2.f32(float [[MUL]]) +; CHECK-NEXT: [[RES:%.*]] = fpext float [[EXP2]] to double ; CHECK-NEXT: ret double [[RES]] ; %subfp = uitofp i31 %x to float |