[PATCH] D88066: [InstCombine] For pow(x, +/-0.5), stop falling into pow(x, 1.5), etc. case

Hubert Tong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 11:23:54 PDT 2020


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6801950192ff: [InstCombine] For pow(x, +/-0.5), stop falling into pow(x, 1.5), etc. case (authored by hubert.reinterpretcast).

Changed prior to commit:
  https://reviews.llvm.org/D88066?vs=293328&id=293536#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88066/new/

https://reviews.llvm.org/D88066

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


Index: llvm/test/Transforms/InstCombine/pow-4.ll
===================================================================
--- llvm/test/Transforms/InstCombine/pow-4.ll
+++ llvm/test/Transforms/InstCombine/pow-4.ll
@@ -234,6 +234,24 @@
   ret <4 x float> %1
 }
 
+; (float)pow((double)(float)x, 0.5)
+; FIXME: One call to `sqrtf` would suffice (PR47613).
+define float @shrink_pow_libcall_half(float %x) {
+; SQRT-LABEL: @shrink_pow_libcall_half(
+; SQRT-NEXT:    [[SQRTF:%.*]] = call fast float @sqrtf(float [[X:%.*]])
+; SQRT-NEXT:    [[SQRTF1:%.*]] = call fast float @sqrtf(float [[X]])
+; SQRT-NEXT:    ret float [[SQRTF1]]
+;
+; NOSQRT-LABEL: @shrink_pow_libcall_half(
+; NOSQRT-NEXT:    [[SQRTF:%.*]] = call fast float @sqrtf(float [[X:%.*]])
+; NOSQRT-NEXT:    ret float [[SQRTF]]
+;
+  %dx = fpext float %x to double
+  %call = call fast double @pow(double %dx, double 0.5)
+  %fr = fptrunc double %call to float
+  ret float %fr
+}
+
 ; Make sure that -0.0 exponent is always simplified.
 
 define double @PR43233(double %x) {
Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1722,7 +1722,8 @@
 
   // pow(x, n) -> x * x * x * ...
   const APFloat *ExpoF;
-  if (AllowApprox && match(Expo, m_APFloat(ExpoF))) {
+  if (AllowApprox && match(Expo, m_APFloat(ExpoF)) &&
+      !ExpoF->isExactlyValue(0.5) && !ExpoF->isExactlyValue(-0.5)) {
     // We limit to a max of 7 multiplications, thus the maximum exponent is 32.
     // If the exponent is an integer+0.5 we generate a call to sqrt and an
     // additional fmul.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88066.293536.patch
Type: text/x-patch
Size: 1700 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200922/c75b3002/attachment.bin>


More information about the llvm-commits mailing list