Skip to content

[WIP] Fix suboptimal codegen for BitConverter.SingleToInt32Bits#7

Draft
Copilot wants to merge 1 commit into
cca-eval-controlfrom
copilot/fix-codegen-bug-bitconverter
Draft

[WIP] Fix suboptimal codegen for BitConverter.SingleToInt32Bits#7
Copilot wants to merge 1 commit into
cca-eval-controlfrom
copilot/fix-codegen-bug-bitconverter

Conversation

Copilot AI commented May 27, 2026

Copy link
Copy Markdown

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.


This section details on the original issue you should resolve

<issue_title>[control] Suboptimal codegen for BitConverter.SingleToInt32Bits in a hot Span loop on x64</issue_title>
<issue_description>

Description

In an x64 release build, calls to BitConverter.SingleToInt32Bits inside a tight loop over a Span<float> produce a stack roundtrip instead of a direct movd r32, xmm. The unnecessary store/reload is observable as a throughput regression on a small BenchmarkDotNet microbenchmark vs the previous release.

Repro

[Benchmark]
public int SumBits(Span<float> input)
{
    int acc = 0;
    foreach (var f in input)
        acc += BitConverter.SingleToInt32Bits(f);
    return acc;
}

Expected disasm (per element)

movd  eax, xmm0
add   ...

Actual disasm (per element)

movss dword ptr [rsp+0x..], xmm0
mov   eax, dword ptr [rsp+0x..]
add   ...

Notes

Likely a JIT-side fix in the intrinsic recognition / lowering path. A disasm-check test under src/tests/JIT/ would be a good way to lock it in.
</issue_description>

Comments on the Issue (you are @copilot in this section)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[control] Suboptimal codegen for BitConverter.SingleToInt32Bits in a hot Span<float> loop on x64

2 participants