[PATCH] D102672: [ConstantFolding] Use APFloat for constant folding. NFC

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 19 11:19:46 PDT 2021


efriedma added inline comments.


================
Comment at: llvm/lib/Analysis/ConstantFolding.cpp:2146
     case LibFunc_logf_finite:
-      if (V > 0.0 && TLI->has(Func))
-        return ConstantFoldFP(log, V, Ty);
+      if (!APF.isNegative() && !APF.isZero() && TLI->has(Func))
+        return ConstantFoldFP(log, APF, Ty);
----------------
sepavloff wrote:
> efriedma wrote:
> > sepavloff wrote:
> > > efriedma wrote:
> > > > This isn't precisely equivalent to the existing code.
> > > Could you please point out the case when this code behaves differently from the existing one?
> > This handles NaNs differently.
> Strictly speaking you are right. Comparison in C is ordered, so `V > 0.0` gives `false for NaN and `ConstantFoldFP` is not called. However all these functions (`log*` and `sqrt*`) have specified behavior when their argument is NaN, so the final result must be the same. Other similar functions like `sin` are called for NaN arguments.
> 
If you want to change this, please add test coverage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102672



More information about the llvm-commits mailing list