JIT: Accelerate floating->long casts on x86#125180
Merged
tannergooding merged 11 commits intodotnet:mainfrom Apr 29, 2026
Merged
JIT: Accelerate floating->long casts on x86#125180tannergooding merged 11 commits intodotnet:mainfrom
tannergooding merged 11 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends x86 JIT codegen to hardware-accelerate non-overflow floating→long/ulong casts using AVX-512 and AVX10.2, completing the remaining cast-acceleration work pulled from #116805.
Changes:
- Teach cast helper selection to allow floating↔long casts to stay intrinsic-based on x86 when AVX-512 is available.
- Add/extend x86 long decomposition logic to generate AVX-512/AVX10.2 sequences for floating→long/ulong and long→floating casts.
- Introduce a new AVX-512 scalar compare-mask intrinsic and wire it up for immediate bounds + containment.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/jit/lowerxarch.cpp | Refactors vector constant construction and adds containment support for the new AVX-512 scalar compare-mask intrinsic. |
| src/coreclr/jit/hwintrinsicxarch.cpp | Adds immediate upper-bound handling for the new AVX-512 scalar compare-mask intrinsic. |
| src/coreclr/jit/hwintrinsiclistxarch.h | Introduces AVX512.CompareScalarMask as a new intrinsic mapping to vcmpss/vcmpsd with IMM. |
| src/coreclr/jit/flowgraph.cpp | Updates helper-requirement logic so x86 floating↔long casts can avoid helper calls when AVX-512 is available. |
| src/coreclr/jit/decomposelongs.cpp | Implements the AVX-512/AVX10.2-based lowering/decomposition sequences for floating↔long/ulong on x86. |
Member
Author
|
@dotnet/jit-contrib this is ready for review |
Member
|
@EgorBo, please review this community PR. |
This was referenced Apr 13, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
src/coreclr/jit/flowgraph.cpp:1347
fgCastRequiresHelperon x86 currently only exempts long<->floating casts whenInstructionSet_AVX512is enabled. This PR adds long/floating cast acceleration that can use AVX10.2 (InstructionSet_AVX10v2) as well (e.g.,DecomposeLongs::DecomposeCastcheckscompOpportunisticallyDependsOn(InstructionSet_AVX10v2)). If AVX10v2 is enabled while AVX512 is disabled/unavailable, morphing may still force a helper call and bypass the new codegen. Consider updating the x86 condition to treat AVX10v2 as sufficient (e.g., require helper only when neither AVX512 nor AVX10v2 is available).
#if defined(TARGET_X86) || defined(TARGET_ARM)
if ((varTypeIsLong(fromType) && varTypeIsFloating(toType)) ||
(varTypeIsFloating(fromType) && varTypeIsLong(toType)))
{
#if defined(TARGET_X86)
return !compOpportunisticallyDependsOn(InstructionSet_AVX512);
#else
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This was referenced Apr 20, 2026
tannergooding
approved these changes
Apr 22, 2026
Member
Author
|
Pushed a change to simplify the IR. No change to the codegen. |
This was referenced Apr 23, 2026
tannergooding
approved these changes
Apr 23, 2026
kg
approved these changes
Apr 29, 2026
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.
This adds floating->long/ulong cast codegen for AVX-512 and AVX10.2 on x86. With this, all non-overflow casts are now hardware accelerated. This is the last bit pulled from #116805.
Typical Diff (double->long AVX-512):
Full Diffs
Breakdown of the double->long asm: