[llvm] [LangRef] make consequences of NaN rules for pow(i) more explicit (PR #170177)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 2 13:16:37 PST 2025


================
@@ -16831,6 +16836,11 @@ trapping or setting ``errno``.
 When specified with the fast-math-flag 'afn', the result may be approximated
 using a less accurate calculation.
 
+Note that due to how :ref:`LLVM treats NaN values <floatnan>`, the special cases
----------------
efriedma-quic wrote:

https://llvm.org/docs/LangRef.html#behavior-of-floating-point-nan-values has the basic rule: "Floating-point math operations are allowed to treat all NaNs as if they were quiet NaNs."

It explicit calls out "For example, 'pow(1.0, SNaN)' may be simplified to 1.0."  Or in other words, `pow(1.0, SNaN)` is non-deterministic: it returns either 1.0 (if we fold it), or some NaN from the allowed set of NaNs (if we don't fold it).

That said, maybe we should go into less detail here to avoid explaining the rules in multiple places.  Just say "note this operation can return a non-NaN result given an SNaN input; see https://llvm.org/docs/LangRef.html#behavior-of-floating-point-nan-values for details".

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


More information about the llvm-commits mailing list