@@ -3394,17 +3394,41 @@ Floating-Point Environment
3394
3394
The default LLVM floating-point environment assumes that traps are disabled and
3395
3395
status flags are not observable. Therefore, floating-point math operations do
3396
3396
not have side effects and may be speculated freely. Results assume the
3397
- round-to-nearest rounding mode.
3397
+ round-to-nearest rounding mode, and subnormals are assumed to be preserved.
3398
+ Running default LLVM code in an environment where these assumptions are not met
3399
+ can lead to undefined behavior.
3400
+
3401
+ The representation bits of a floating-point value do not mutate arbitrarily; if
3402
+ there is no floating-point operation being performed, the NaN payload (if any)
3403
+ is preserved.
3404
+
3405
+ When a floating-point math operation produces a NaN value, the result has a
3406
+ non-deterministic sign. The payload is non-deterministically chosen from the
3407
+ following set:
3408
+
3409
+ - The payload that is all-zero except that the ``quiet`` bit is set.
3410
+ ("Preferred NaN" case)
3411
+ - The payload of any input operand that is a NaN, bit-wise ORed with a payload that has
3412
+ the ``quiet`` bit set. ("Quieting NaN propagation" case)
3413
+ - The payload of any input operand that is a NaN. ("Unchanged NaN propagation" case)
3414
+ - A target-specific set of further NaN payloads, that definitely all have their
3415
+ ``quiet`` bit set. The set can depend on the payloads of the input NaNs.
3416
+ This set is empty on x86 and ARM, but can be non-empty on other architectures.
3417
+ (For instance, on wasm, if any input NaN is not the preferred NaN, then
3418
+ this set contains all quiet NaNs; otherwise, it is empty.
3419
+ On SPARC, this set consists of the all-one payload.)
3420
+
3421
+ In particular, if all input NaNs are quiet, then the output NaN is definitely
3422
+ quiet. Signaling NaN outputs can only occur if they are provided as an input
3423
+ value. For example, "fmul SNaN, 1.0" may be simplified to SNaN rather than QNaN.
3398
3424
3399
3425
Floating-point math operations are allowed to treat all NaNs as if they were
3400
- quiet NaNs. For example, "pow(1.0, SNaN)" may be simplified to 1.0. This also
3401
- means that SNaN may be passed through a math operation without quieting. For
3402
- example, "fmul SNaN, 1.0" may be simplified to SNaN rather than QNaN. However,
3403
- SNaN values are never created by math operations. They may only occur when
3404
- provided as a program input value.
3426
+ quiet NaNs. For example, "pow(1.0, SNaN)" may be simplified to 1.0.
3405
3427
3406
3428
Code that requires different behavior than this should use the
3407
3429
:ref:`Constrained Floating-Point Intrinsics <constrainedfp>`.
3430
+ In particular, constrained intrinsics rule out the "Unchanged NaN propagation" case;
3431
+ they are guaranteed to return a QNaN.
3408
3432
3409
3433
.. _fastmath:
3410
3434
0 commit comments