Skip to content

JIT: Accelerate uint->floating casts on pre-AVX-512 x86#124114

Open
saucecontrol wants to merge 2 commits intodotnet:mainfrom
saucecontrol:lng2flt5
Open

JIT: Accelerate uint->floating casts on pre-AVX-512 x86#124114
saucecontrol wants to merge 2 commits intodotnet:mainfrom
saucecontrol:lng2flt5

Conversation

@saucecontrol
Copy link
Member

@saucecontrol saucecontrol commented Feb 7, 2026

This is another one peeled from #116805 (only one more to go after this 😄)

It takes care of uint->floating casts without a helper call on pre-AVX-512 x86. Since baseline x86 is the only platform without native instructions for all 32-bit conversions, adding this allows some more simplification in fgMorphExpandCast

Typical diff:

-       push     eax
-       vzeroupper 
-       push     0
-       push     ecx
-       call     [CORINFO_HELP_LNG2FLT]
-       fstp     dword ptr [esp]
-       vmovss   xmm0, dword ptr [esp]
+       vxorps   xmm0, xmm0, xmm0
+       vcvtsi2sd xmm0, xmm0, ecx
+       vaddsd   xmm1, xmm0, qword ptr [reloc @RWD00]
+       vblendvpd xmm0, xmm0, xmm1, xmm0
+       vcvtpd2ps xmm0, xmm0
        vmovd    eax, xmm0
-       pop      ecx
        ret      

+RWD00  	dq	41F0000000000000h
 
-; Total bytes of code 27
+; Total bytes of code 31

Copilot AI review requested due to automatic review settings February 7, 2026 00:18
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 7, 2026
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 7, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the JIT’s cast handling to avoid helper calls for uint → floating-point conversions on pre-AVX-512 x86, while also centralizing the “cast requires helper” decision logic to simplify fgMorphExpandCast.

Changes:

  • Add Compiler::fgCastRequiresHelper and use it from importer/morph to consolidate helper-call decisions for casts.
  • Implement x86 lowering for uintfloat/double casts without helper calls when AVX-512 unsigned-convert is unavailable.
  • Adjust cast handling/refactoring in fgMorphExpandCast and AVX-512 long→floating decomposition codepaths.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/coreclr/jit/morph.cpp Refactors cast expansion to use fgCastRequiresHelper and simplifies helper selection logic.
src/coreclr/jit/lowerxarch.cpp Adds x86 lowering sequence for uint→floating casts without helper calls (pre-AVX-512 path).
src/coreclr/jit/importer.cpp Replaces ad-hoc helper decision logic with fgCastRequiresHelper.
src/coreclr/jit/flowgraph.cpp Introduces fgCastRequiresHelper implementation.
src/coreclr/jit/decomposelongs.cpp Minor refactor/clarification for AVX-512 long→floating cast decomposition.
src/coreclr/jit/compiler.h Declares fgCastRequiresHelper.

@saucecontrol saucecontrol marked this pull request as ready for review February 7, 2026 05:24
Copilot AI review requested due to automatic review settings February 7, 2026 05:24
@saucecontrol
Copy link
Member Author

@dotnet/jit-contrib this is ready for review.

Diffs show an odd throughput regression for Windows x64. Looks like it might just be lack of /LTCG?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant