Skip to content

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

Merged
jakobbotsch merged 1 commit into
dotnet:mainfrom
saucecontrol:fix-small-cast
Feb 25, 2025
Merged

JIT: Fix small->uint->float casts with AVX-512#112892
jakobbotsch merged 1 commit into
dotnet:mainfrom
saucecontrol:fix-small-cast

Conversation

@saucecontrol

@saucecontrol saucecontrol commented Feb 25, 2025

Copy link
Copy Markdown
Member

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

Comment thread src/coreclr/jit/lowerxarch.cpp

@jakobbotsch jakobbotsch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for fixing this.

@jakobbotsch
jakobbotsch merged commit 8017079 into dotnet:main Feb 25, 2025
@saucecontrol
saucecontrol deleted the fix-small-cast branch February 25, 2025 20:03
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 28, 2025
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 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

2 participants