[PATCH] D64099: [InstCombine] pow(C,x) -> exp2(log2(C)*x)

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 2 16:33:36 PDT 2019


xbolva00 marked an inline comment as done.
xbolva00 added inline comments.


================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:1354
+    Value *LogC =
+        emitUnaryFloatFnCall(ConstantFP::get(Ty, *BaseF), "log", B, Attrs);
+    Value *FMul = B.CreateFMul(LogC, Expo, "logmul");
----------------
efriedma wrote:
> xbolva00 wrote:
> > xbolva00 wrote:
> > > efriedma wrote:
> > > > I'd rather explicitly fold the "log" here, so we know it actually happens; the constant folding code will not fold it in all cases.
> > > emitUnaryFloatFnCall automatically folds it? @spatel @lebedev.ri 
> > > 
> > > Not sure how to get log2 of APFloat...
> > Ah, right. It was constant folded only in “fast” mode..
> lib/Analysis/ConstantFolding.cpp has some code that calls APFloat::convertToDouble() and uses the host C library's implementation of various routines: specifically, fabs, log2, log, log10, exp, exp2, sin, cos, sqrt, acos, asin, atan, ceil, cosh, exp, floor, round, sinh, tan, tanh, pow, fmod, atan2.  This is not ideal, but the trigonometric and exponential functions are tricky to implement with correct rounding, and nobody has spent the time to implement them on APFloat.
> 
> It's worth noting that we never fold the long double versions.
Thanks, I will use this solution.


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

https://reviews.llvm.org/D64099





More information about the llvm-commits mailing list