Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Fix small->uint->float casts with AVX-512 #112892

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

saucecontrol
Copy link
Member

@saucecontrol saucecontrol commented Feb 25, 2025

Fixes #112871

In lowering, we had logic that inserted an intermediate cast to int when casting small types to/from floating. The float->small case was already handled by morph and will not appear in lowering. The other direction doesn't require a cast as long as the small type is handled correctly in the containment check and codegen.

The extra cast that was being inserted broke small->uint->floating conversions, for which uint->floating is now handled directly by AVX-512 instructions.

Diffs show a few hits where the uint->floating conversion instruction is restored, but all cases are on loads of unsigned small types where it wouldn't matter.

        movzx    rax, byte  ptr [rbp-0x0F]
        vxorps   xmm0, xmm0, xmm0
-       vcvtsi2sd xmm0, xmm0, eax
+       vcvtusi2sd xmm0, xmm0, eax

I've added a regression test for the Fuzzlyn example, which does fail without the fix.

There are a few improvements as well. I removed a restriction on containment of memory operands for ulong->floating casts when we can use the AVX-512 conversion instructions:

-       mov      rax, qword ptr [rdi]
        vxorps   xmm0, xmm0, xmm0
-       vcvtusi2ss xmm0, xmm0, rax
+       vcvtusi2ss xmm0, xmm0, qword ptr [rdi]

And we're now skipping the insertion of unnecessary int casts, which eliminates some movs:

-       mov      eax, esi
        vxorps   xmm1, xmm1, xmm1
-       vcvtsi2ss xmm1, xmm1, eax
+       vcvtsi2ss xmm1, xmm1, esi

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.

JIT: Wrong result with double comparison
1 participant