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

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 2 16:08:58 PDT 2019


efriedma 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");
----------------
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.


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

https://reviews.llvm.org/D64099





More information about the llvm-commits mailing list