Skip to content

Commit

Permalink
[LangRef] improve documentation of SNaN in the default FP environment
Browse files Browse the repository at this point in the history
Make it explicit that SNaN is not handled differently than
QNaN in the LLVM default floating-point environment.

Note that an IEEE-754-compliant model disallows transforms
like "X * 1.0 -> X". That is because math operations are
expected to convert SNaN to QNaN (set the signaling bit).

But LLVM has had those kinds of transforms from the beginning:
https://alive2.llvm.org/ce/z/igb55y

We should be IEEE-754-compliant under strict-FP (the logic is
implemented with a helper named canIgnoreSNaN()), but I don't
think there is any demand to do that with default optimization.

See issue #43070 for earlier draft/discussion about this change.

Differential Revision: https://reviews.llvm.org/D143074
  • Loading branch information
rotateright committed Feb 15, 2023
1 parent 7a282bd commit 4c34086
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions llvm/docs/LangRef.rst
Expand Up @@ -3284,15 +3284,17 @@ seq\_cst total orderings of other operations that are not marked
Floating-Point Environment
--------------------------

The default LLVM floating-point environment assumes that floating-point
instructions do not have side effects. Results assume the round-to-nearest
rounding mode. No floating-point exception state is maintained in this
environment. Therefore, there is no attempt to create or preserve invalid
operation (SNaN) or division-by-zero exceptions.

The benefit of this exception-free assumption is that floating-point
operations may be speculated freely without any other fast-math relaxations
to the floating-point model.
The default LLVM floating-point environment assumes that traps are disabled and
status flags are not observable. Therefore, floating-point math operations do
not have side effects and may be speculated freely. Results assume the
round-to-nearest rounding mode.

Floating-point math operations are allowed to treat all NaNs as if they were
quiet NaNs. For example, "pow(1.0, SNaN)" may be simplified to 1.0. This also
means that SNaN may be passed through a math operation without quieting. For
example, "fmul SNaN, 1.0" may be simplified to SNaN rather than QNaN. However,
SNaN values are never created by math operations. They may only occur when
provided as a program input value.

Code that requires different behavior than this should use the
:ref:`Constrained Floating-Point Intrinsics <constrainedfp>`.
Expand Down

0 comments on commit 4c34086

Please sign in to comment.