[llvm-dev] [754] Fold FP "Op SNaN" to QNaN?

Jacob Lifshay via llvm-dev llvm-dev at lists.llvm.org
Fri Jul 9 12:17:31 PDT 2021


On Fri, Jul 9, 2021, 11:58 Kevin Neal via llvm-dev <llvm-dev at lists.llvm.org>
wrote:

> Yes, true.
>
>
>
> This came up in the context of adding support for the constrained FP
> intrinsics. These intrinsics all include a metadata argument for specifying
> how important FP traps are. If traps are “strict” then we can’t fold away
> any traps. The default FP environment would use “ignore” where there are no
> traps and folding is fine. I’m working on the “maytrap” case where we can
> eliminate traps but cannot introduce any new ones. More on constrained
> intrinsics:
> https://llvm.org/docs/LangRef.html#constrained-floating-point-intrinsics
>

Afaict converting SNaN inputs to QNaN should be fine for maytrap,
excluding, of course, things like fneg and copysign that just manipulate
bits. If LLVM wants to guarantee correct NaN bits in the output, be aware
that some platforms have special cases for SNaN -> QNaN: RISC-V always
produces the canonical NaN, MIPS pre-2008-mode has the quiet bit inverted
from the usual, so a SNaN mantissa with a 1 MSB and the rest zeros needs to
adjust the mantissa to avoid generating an infinity instead of a QNaN.

>
>
>
>
> To be clear, are you saying that my interpretation of 754 is correct?
>

Yes, afaict. I'd suggest waiting for someone else to also check this since
we may be missing some special case...

Jacob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210709/66f11694/attachment.html>


More information about the llvm-dev mailing list