JIT: Transform floating SELECT(a < b, a, b) to NativeMin(a, b)#128402
JIT: Transform floating SELECT(a < b, a, b) to NativeMin(a, b)#128402BoyBaykiller wants to merge 2 commits into
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
54965b8 to
75cee7e
Compare
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.
| // Ensure the operation has integer type. | ||
| if (!varTypeIsIntegralOrI(tree)) | ||
| if (!varTypeIsIntegralOrI(tree) && !varTypeIsFloating(tree)) | ||
| { | ||
| return false; | ||
| } |
| if (select->OperIs(GT_SELECT)) | ||
| { | ||
| #ifdef TARGET_RISCV64 | ||
| JITDUMP("Skipping if-conversion that could not be optimized to ordinary operations\n"); | ||
| return true; | ||
| } | ||
| #endif |
There was a problem hiding this comment.
we call gtNewConditionalNode before which counts as change
|
@MihuBot -nuget |
|
As per Discord, I'm not in favor of this specific optimization. The In general I'd like to push users towards a path of success and accelerating a "bad practice" doesn't help achieve that. |
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