Skip to content

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

@EgorBo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions