[llvm] r365758 - [InstCombine] Reorder recently added/improved pow transformations
David Bolvansky via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 11 03:55:04 PDT 2019
Author: xbolva00
Date: Thu Jul 11 03:55:04 2019
New Revision: 365758
URL: http://llvm.org/viewvc/llvm-project?rev=365758&view=rev
Log:
[InstCombine] Reorder recently added/improved pow transformations
Changed cases are now faster with exp2.
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/trunk/test/Transforms/InstCombine/pow_fp_int.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=365758&r1=365757&r2=365758&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Thu Jul 11 03:55:04 2019
@@ -1471,6 +1471,9 @@ Value *LibCallSimplifier::optimizePow(Ca
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(Ca
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
Modified: llvm/trunk/test/Transforms/InstCombine/pow_fp_int.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/pow_fp_int.ll?rev=365758&r1=365757&r2=365758&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/pow_fp_int.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/pow_fp_int.ll Thu Jul 11 03:55:04 2019
@@ -51,8 +51,10 @@ define double @pow_uitofp_double_const_b
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_b
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
More information about the llvm-commits
mailing list