[llvm] specify NaN behavior more precisely (PR #66579)

Ralf Jung via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 17 01:05:52 PDT 2023


================
@@ -3394,17 +3394,41 @@ Floating-Point Environment
 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.
+round-to-nearest rounding mode, and subnormals are assumed to be preserved.
+Running default LLVM code in an environment where these assumptions are not met
+can lead to undefined behavior.
+
+The representation bits of a floating-point value do not mutate arbitrarily; if
+there is no floating-point operation being performed, the NaN payload (if any)
+is preserved.
----------------
RalfJung wrote:

Yes, that's a bug in the x86-32 backend / calling convention.

Given that this bug is hard-coded in the calling convention, I wonder if it should be called out here. But the main point if this sentence is that LLVM itself will not do anything that would mutate FP values. In fact this bug here leads to miscompilations because LLVM itself *assumes* that FP values don't change -- see https://github.com/llvm/llvm-project/issues/44218.

https://github.com/llvm/llvm-project/pull/66579


More information about the llvm-commits mailing list