Skip to content

Commit 4c34086

Browse files
committed
[LangRef] improve documentation of SNaN in the default FP environment
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
1 parent 7a282bd commit 4c34086

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

llvm/docs/LangRef.rst

+11-9
Original file line numberDiff line numberDiff line change
@@ -3284,15 +3284,17 @@ seq\_cst total orderings of other operations that are not marked
32843284
Floating-Point Environment
32853285
--------------------------
32863286

3287-
The default LLVM floating-point environment assumes that floating-point
3288-
instructions do not have side effects. Results assume the round-to-nearest
3289-
rounding mode. No floating-point exception state is maintained in this
3290-
environment. Therefore, there is no attempt to create or preserve invalid
3291-
operation (SNaN) or division-by-zero exceptions.
3292-
3293-
The benefit of this exception-free assumption is that floating-point
3294-
operations may be speculated freely without any other fast-math relaxations
3295-
to the floating-point model.
3287+
The default LLVM floating-point environment assumes that traps are disabled and
3288+
status flags are not observable. Therefore, floating-point math operations do
3289+
not have side effects and may be speculated freely. Results assume the
3290+
round-to-nearest rounding mode.
3291+
3292+
Floating-point math operations are allowed to treat all NaNs as if they were
3293+
quiet NaNs. For example, "pow(1.0, SNaN)" may be simplified to 1.0. This also
3294+
means that SNaN may be passed through a math operation without quieting. For
3295+
example, "fmul SNaN, 1.0" may be simplified to SNaN rather than QNaN. However,
3296+
SNaN values are never created by math operations. They may only occur when
3297+
provided as a program input value.
32963298

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

0 commit comments

Comments
 (0)