Use LLVM intrinsics for NaN-propagating float min and max#5114
Merged
SeanTAllen merged 1 commit intomainfrom Apr 4, 2026
Merged
Use LLVM intrinsics for NaN-propagating float min and max#5114SeanTAllen merged 1 commit intomainfrom
SeanTAllen merged 1 commit intomainfrom
Conversation
SeanTAllen
added a commit
that referenced
this pull request
Apr 4, 2026
812db8d to
f1c9cdd
Compare
The conditional implementation (`if this < y then this else y end`) is asymmetric when NaN is involved: IEEE 754 comparisons with NaN return false, so the else branch always fires when `this` is NaN but not when `y` is NaN. The result depends on argument order, which is wrong. LLVM's `llvm.minimum`/`llvm.maximum` intrinsics implement IEEE 754-2019 NaN-propagating semantics — if either operand is NaN, the result is NaN. Closes #5089
f1c9cdd to
702ea79
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
F32/F64
min/maxusedif this < y then this else y end, which is asymmetric with NaN. IEEE 754 comparisons involving NaN returnfalse, so theelsebranch always fires whenthisis NaN but not whenyis NaN —NaN.min(5.0)returned5.0butF32(5.0).min(NaN)returnedNaN.Replaced with LLVM
llvm.minimum/llvm.maximumintrinsics which implement IEEE 754-2019 NaN-propagating semantics: if either operand is NaN, the result is NaN. Integermin/maxare unchanged.Closes #5089