From: David Bolvansky Date: Thu, 11 Jul 2019 10:55:04 +0000 (+0000) Subject: [InstCombine] Reorder recently added/improved pow transformations X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0f3d79f3e7958d4240616897d09e996245ac0f5c;p=llvm [InstCombine] Reorder recently added/improved pow transformations Changed cases are now faster with exp2. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365758 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp index b481d2b50a8..bc55e77c44f 100644 --- a/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/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(Expo) || isa(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/test/Transforms/InstCombine/pow_fp_int.ll b/test/Transforms/InstCombine/pow_fp_int.ll index f89353cd707..372a9e11c1e 100644 --- a/test/Transforms/InstCombine/pow_fp_int.ll +++ b/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