[llvm] fa2783d - [InstCombine] Remove hasOneUse check for pow(C, x) -> exp2(log2(C)*x)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue May 5 06:46:21 PDT 2020
Author: Jay Foad
Date: 2020-05-05T14:46:08+01:00
New Revision: fa2783d79a233468ac8630361d9b75512c0cb2bd
URL: https://github.com/llvm/llvm-project/commit/fa2783d79a233468ac8630361d9b75512c0cb2bd
DIFF: https://github.com/llvm/llvm-project/commit/fa2783d79a233468ac8630361d9b75512c0cb2bd.diff
LOG: [InstCombine] Remove hasOneUse check for pow(C,x) -> exp2(log2(C)*x)
I don't think there's any good reason not to do this transformation when
the pow has multiple uses.
Differential Revision: https://reviews.llvm.org/D79407
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/pow-exp.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index c45ef8810ac5..01bf124fcb06 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1564,8 +1564,8 @@ Value *LibCallSimplifier::replacePowWithExp(CallInst *Pow, IRBuilderBase &B) {
LibFunc_exp10l, B, Attrs);
// pow(n, x) -> exp2(log2(n) * x)
- if (Pow->hasOneUse() && Pow->hasApproxFunc() && Pow->hasNoNaNs() &&
- Pow->hasNoInfs() && BaseF->isNormal() && !BaseF->isNegative()) {
+ if (Pow->hasApproxFunc() && Pow->hasNoNaNs() && Pow->hasNoInfs() &&
+ BaseF->isNormal() && !BaseF->isNegative()) {
Value *Log = nullptr;
if (Ty->isFloatTy())
Log = ConstantFP::get(Ty, std::log2(BaseF->convertToFloat()));
diff --git a/llvm/test/Transforms/InstCombine/pow-exp.ll b/llvm/test/Transforms/InstCombine/pow-exp.ll
index a583c367e4dd..7fc00527288d 100644
--- a/llvm/test/Transforms/InstCombine/pow-exp.ll
+++ b/llvm/test/Transforms/InstCombine/pow-exp.ll
@@ -350,9 +350,10 @@ define double @pow_negative_base(double %e) {
define double @pow_multiuse(double %e) {
; CHECK-LABEL: @pow_multiuse(
-; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn double @pow(double 5.000000e+00, double [[E:%.*]])
-; CHECK-NEXT: tail call void @use_d(double [[CALL]])
-; CHECK-NEXT: ret double [[CALL]]
+; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn double [[E:%.*]], 0x4002934{{.*}}
+; CHECK-NEXT: [[EXP2:%.*]] = call nnan ninf afn double @exp2(double [[MUL]])
+; CHECK-NEXT: tail call void @use_d(double [[EXP2]])
+; CHECK-NEXT: ret double [[EXP2]]
;
%call = tail call afn nnan ninf double @pow(double 5.000000e+00, double %e)
tail call void @use_d(double %call)
@@ -433,9 +434,10 @@ define float @powf_negative_base(float %e) {
define float @powf_multiuse(float %e) {
; CHECK-LABEL: @powf_multiuse(
-; CHECK-NEXT: [[CALL:%.*]] = tail call nnan ninf afn float @powf(float 5.000000e+00, float [[E:%.*]])
-; CHECK-NEXT: tail call void @use_f(float [[CALL]])
-; CHECK-NEXT: ret float [[CALL]]
+; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn float [[E:%.*]], 0x4002934{{.*}}
+; CHECK-NEXT: [[EXP2F:%.*]] = call nnan ninf afn float @exp2f(float [[MUL]])
+; CHECK-NEXT: tail call void @use_f(float [[EXP2F]])
+; CHECK-NEXT: ret float [[EXP2F]]
;
%call = tail call afn nnan ninf float @powf(float 5.000000e+00, float %e)
tail call void @use_f(float %call)
More information about the llvm-commits
mailing list