JIT: Transform floating SELECT(a < b, a, b) to NativeMin(a, b)#128402
Draft
BoyBaykiller wants to merge 2 commits into
Draft
JIT: Transform floating SELECT(a < b, a, b) to NativeMin(a, b)#128402BoyBaykiller wants to merge 2 commits into
BoyBaykiller wants to merge 2 commits into
Conversation
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
54965b8 to
75cee7e
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends CoreCLR JIT if-conversion select optimization to recognize floating-point conditional selects that compute min/max (e.g., a < b ? a : b) and replace them with a native SIMD min/max node on xarch, enabling codegen like vminss/vmaxss instead of compare + branch.
Changes:
- Allow
GT_STORE_LCL_VAR/GT_RETURNif-conversion when the value type is floating-point (in addition to integral/I). - Add
TrySelectToMinMaxto rewrite eligible floatingGT_SELECTnodes intogtNewSimdMinMaxNativeNode(xarch). - Add an early bailout to avoid producing floating-point
GT_SELECTnodes unless they optimize to a non-SELECT form.
Comment on lines
208
to
212
| // Ensure the operation has integer type. | ||
| if (!varTypeIsIntegralOrI(tree)) | ||
| if (!varTypeIsIntegralOrI(tree) && !varTypeIsFloating(tree)) | ||
| { | ||
| return false; | ||
| } |
Comment on lines
640
to
645
| if (select->OperIs(GT_SELECT)) | ||
| { | ||
| #ifdef TARGET_RISCV64 | ||
| JITDUMP("Skipping if-conversion that could not be optimized to ordinary operations\n"); | ||
| return true; | ||
| } | ||
| #endif |
Contributor
Author
There was a problem hiding this comment.
we call gtNewConditionalNode before which counts as change
Contributor
Author
|
@MihuBot -nuget |
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.
Example:
Handles all these cases. I compared the codegen of every single one against it to be sure its correct:
https://godbolt.org/z/389jvnfW4
Fix #116802