[PATCH] D79407: [InstCombine] Remove hasOneUse check for pow(C, x) -> exp2(log2(C)*x)

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 5 04:48:40 PDT 2020


foad created this revision.
foad added reviewers: xbolva00, spatel, efriedma, evandro.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

I don't think there's any good reason not to do this transformation when
the pow has multiple uses.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79407

Files:
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/InstCombine/pow-exp.ll


Index: llvm/test/Transforms/InstCombine/pow-exp.ll
===================================================================
--- llvm/test/Transforms/InstCombine/pow-exp.ll
+++ llvm/test/Transforms/InstCombine/pow-exp.ll
@@ -350,9 +350,10 @@
 
 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_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)
Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1564,8 +1564,8 @@
                                 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()));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79407.262064.patch
Type: text/x-patch
Size: 2303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200505/8b877b3a/attachment.bin>


More information about the llvm-commits mailing list