[release/8.0-staging] Ensure that the various Max*Number and Min*Number APIs optimize correctly
#98159
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.
Backport of #98125 to release/8.0-staging
/cc @tannergooding
Customer Impact
Developers calling
MaxNumberorMinNumberwith one constant input may seeNaNpropagated instead of the number. This results in incorrect results as these APIs are explicitly meant to not propagate the NaN.Regression
This was introduced in .NET 8 as part of AVX-512 related acceleration work. The actual underlying issue was simple: we were swapping the operands as intended, but then re-swapped them back when actually modifying the node.
Testing
Tests were added covering the scenario in a way that explicitly ensures the JIT can only see one of the inputs as constant. If the JIT happened to see both inputs as constant, such as due to other optimizations, the value would have been correct.
Risk
Low. The issue was a simple one that was missed in code review and testing due to involving partial constant folding. It impacts a small set of math APIs, which themselves are relatively new to .NET (new in .NET 7)