[PATCH] D79413: [InstCombine] Allow denormal C in pow(C,y) -> exp2(log2(C)*y)

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 5 05:53:03 PDT 2020


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

We check that C is finite and strictly positive, but there's no need to
check that it's normal too. exp2 should be just as accurate on denormals
as pow is.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79413

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
@@ -261,6 +261,16 @@
   ret double %call
 }
 
+define double @pow_ok_denorm_base(double %e) {
+; CHECK-LABEL: @pow_ok_denorm_base(
+; CHECK-NEXT:    [[MUL:%.*]] = fmul nnan ninf afn double [[E:%.*]], 0xC0904800000005C5
+; CHECK-NEXT:    [[EXP2:%.*]] = call nnan ninf afn double @exp2(double [[MUL]])
+; CHECK-NEXT:    ret double [[EXP2]]
+;
+  %call = tail call afn nnan ninf double @pow(double 0x00000000FFFFFFFF, double %e)
+  ret double %call
+}
+
 define float @powf_ok_base(float %e) {
 ; CHECK-LABEL: @powf_ok_base(
 ; CHECK-NEXT:    [[MUL:%.*]] = fmul nnan ninf afn float [[E:%.*]], 0xBFE07762{{.*}}
@@ -301,6 +311,16 @@
   ret float %call
 }
 
+define float @powf_ok_denorm_base(float %e) {
+; CHECK-LABEL: @powf_ok_denorm_base(
+; CHECK-NEXT:    [[MUL:%.*]] = fmul nnan ninf afn float [[E:%.*]], -1.350000e+02
+; CHECK-NEXT:    [[EXP2F:%.*]] = call nnan ninf afn float @exp2f(float [[MUL]])
+; CHECK-NEXT:    ret float [[EXP2F]]
+;
+  %call = tail call afn nnan ninf float @powf(float 0x3780000000000000, float %e)
+  ret float %call
+}
+
 ; Negative tests
 
 define double @pow_zero_base(double %e) {
Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1565,7 +1565,7 @@
 
   // pow(n, x) -> exp2(log2(n) * x)
   if (Pow->hasOneUse() && Pow->hasApproxFunc() && Pow->hasNoNaNs() &&
-      Pow->hasNoInfs() && BaseF->isNormal() && !BaseF->isNegative()) {
+      Pow->hasNoInfs() && BaseF->isFiniteNonZero() && !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: D79413.262080.patch
Type: text/x-patch
Size: 1956 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200505/b055c5c9/attachment.bin>


More information about the llvm-commits mailing list