[PATCH] D106362: [FPEnv][InstSimplify] Enable more folds for constrained fadd

Serge Pavlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 2 10:57:15 PDT 2021


sepavloff added inline comments.


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4908
+      (!RoundingModeMayBe(Rounding, RoundingMode::TowardNegative) &&
+       (ExBehavior != fp::ebStrict || FMF.noNaNs())))
+    if (match(Op1, m_NegZeroFP()))
----------------
kpn wrote:
> sepavloff wrote:
> > Even if `ExBehavior != fp::ebStrict` this transformation is invalid if `X` is SNaN, the latter must be converted to QNaN.
> > 
> > 
> Can I put this in a different patch? We have the same issue for constrained and non-constrained cases, and we don't have a good way to distinguish them -- nor should we.
> 
> Most of the required code is present in APFloat, but not all. Would it be OK for me to add the needed bits to APFloat and use them from InstSimplify in a different ticket?
I am not sure I understand what you are going to put into another patch. The transformation:

    fadd X, -0 ==> X

is valid only if `X != SNaN`, otherwise we have:

    fadd SNaN, -0 ==> QNaN

It does not depend on whether FP environment is default or not, the code before your changes was already incorrect. Such transformation is valid if the operation has flag `nnan`, but not in general case. Code in APFloat hardly can help, as constant folding is made previously, if `X` is a constant here, it means it cannot be folded.


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

https://reviews.llvm.org/D106362



More information about the llvm-commits mailing list