Skip to content

Suboptimal codegen for Math.DivRem(x, CONST) #117215

Open

Description

@EgorBo

From #117160 (comment)

(uint byteIndex, uint bitOffset) Test(int index)
{
    return Math.DivRem((uint) index, 8);
}

Current codegen:

       mov      eax, edx
       shr      eax, 3
       lea      ecx, [8*rax]
       sub      edx, ecx
       mov      ecx, edx
       shl      rcx, 32
       or       rax, rcx
       ret      
; Total bytes of code: 24

Expected codegen:

       mov      eax, edx
       shr      eax, 3
       and      edx, 7
       mov      ecx, edx
       shl      rcx, 32
       or       rax, rcx
       ret      
; Total bytes of code: 18

Activity

  1. added
    untriaged
    on Jul 1, 2025
  2. added
    area-CodeGen-coreclr
    and removed
    untriaged
    on Jul 1, 2025
  3. added this to the Future milestone on Jul 1, 2025
  4. dotnet-policy-service commented on Jul 1, 2025

    @dotnet-policy-service
    Contributor

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclr

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions