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: Missed optimization for integer x / y; x % y #112774

Closed
BoyBaykiller opened this issue Feb 21, 2025 · 3 comments
Closed

JIT: Missed optimization for integer x / y; x % y #112774

BoyBaykiller opened this issue Feb 21, 2025 · 3 comments
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Comments

@BoyBaykiller
Copy link

For integers this is a common pattern

a = x / y;
b = x % y;

which currently generates (https://godbolt.org/z/nn3b4q57K):

mov      eax, edi
cdq      
idiv     edx:eax, esi          ; compute quotient and remainder
mov      dword ptr [r8], eax   ; a = quotient
mov      eax, edi
cdq      
idiv     edx:eax, esi          ; compute quotient and remainder
mov      dword ptr [rcx], edx  ; b = remainder

div already gives quotient and remainder so it should only be computed once here (https://godbolt.org/z/qKb8qEqzv):

mov     eax, edi
cdq
idiv    esi
mov     dword ptr [r8], eax
mov     dword ptr [rcx], edx
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 21, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 21, 2025
Copy link
Contributor

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

@huoyaoyuan
Copy link
Member

Duplicate of #5213. See also #45230.

Math.DivRem or X86Base.DivRem are the suggested approach.

@EgorBo EgorBo closed this as completed Feb 21, 2025
@EgorBo EgorBo removed the untriaged New issue has not been triaged by the area owner label Feb 21, 2025
@BoyBaykiller
Copy link
Author

Ah I missed these issues and DivRem. It'd still be nice if this was handled in JIT

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
Projects
None yet
Development

No branches or pull requests

3 participants