[llvm] LangRef: Clarify llvm.minnum and llvm.maxnum about sNaN and signed zero (PR #112852)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 21 22:52:22 PST 2025


================
@@ -16723,21 +16723,29 @@ type.
 
 Semantics:
 """"""""""
+Follows the semantics of minimumNumber in IEEE-754-2019, except for signaling NaNs. If either operand
+is an sNaN, the result is always a qNaN. This matches the recommended behavior for the libm
+function ``fmin``, although not all implementations have implemented these recommended behaviors.
+
+If either operand is a qNaN, returns the other non-NaN operand. Returns NaN only if both operands are
+NaN or if either operand is sNaN. Note that arithmetic on an sNaN doesn't consistently produce a qNaN,
+so arithmetic feeding into a minnum can produce inconsistent results. For example,
+`minnum(fadd(sNaN, 0.0), 1.0)` can produce qNaN or 1.0 depending on whether `fadd` is folded.
----------------
arsenm wrote:

```suggestion
`minnum(fadd(sNaN, -0.0), 1.0)` can produce qNaN or 1.0 depending on whether `fadd` is folded.
```

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


More information about the llvm-commits mailing list