Skip to content

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

Merged
tannergooding merged 4 commits into
dotnet:mainfrom
saucecontrol:lng2flt5
Mar 3, 2026
Merged

tannergooding merged 4 commits into
dotnet:mainfrom
saucecontrol:lng2flt5

Conversation

@saucecontrol

@saucecontrol saucecontrol commented Feb 7, 2026 •

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 uint → float/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.

Comment thread src/coreclr/jit/lowerxarch.cpp
@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
Copy Markdown
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?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

@JulieLeeMSFT

Copy link
Copy Markdown
Member

@anthonycanino, @kg @tannergooding PTAL.

@JulieLeeMSFT
JulieLeeMSFT requested a review from kg March 2, 2026 15:49
@JulieLeeMSFT JulieLeeMSFT added the avx512 Related to the AVX-512 architecture label Mar 2, 2026
@JulieLeeMSFT JulieLeeMSFT added this to the 11.0.0 milestone Mar 2, 2026
Comment thread src/coreclr/jit/importer.cpp
Comment thread src/coreclr/jit/lowerxarch.cpp
Comment thread src/coreclr/jit/lowerxarch.cpp
Comment thread src/coreclr/jit/morph.cpp
@kg

kg commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Looks okay to me, going to defer to @tannergooding for the final approval though

Copilot AI review requested due to automatic review settings March 3, 2026 19:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

@saucecontrol

Copy link
Copy Markdown
Member Author

Updated diffs. The mysterious Windows x64 throughput regression I saw last month has resolved itself.

@tannergooding
tannergooding merged commit 3bd006f into dotnet:main Mar 3, 2026
127 of 132 checks passed
@saucecontrol
saucecontrol deleted the lng2flt5 branch March 3, 2026 22:51
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI avx512 Related to the AVX-512 architecture 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.

5 participants