Skip to content

JIT: Simplify arithmetic operations on memory, as is already done for register #125300

@BoyBaykiller

Description

@BoyBaykiller

I expected the reg and mem variant to have same codegen, https://godbolt.org/z/MGzTd3s3c
JitOptRepeat seems to help a little for SubMem only.

static int AddReg(int mem)
{
    int a = mem;
    int b = mem;
    int c = mem;
    int r = a + b + c;
    return r;
}

static int AddMem(ref int mem)
{
    int a = mem;
    int b = mem;
    int c = mem;
    int r = a + b + c;
    return r;
}

static int SubReg(int mem)
{
    int a = mem;
    int b = mem;
    int c = mem;
    int r = a - b - c;
    return r;
}

static int SubMem(ref int mem)
{
    int a = mem;
    int b = mem;
    int c = mem;
    int r = a - b - c;
    return r;
}
Program:AddReg(int):int (FullOpts):
       lea      eax, [rdi+2*rdi]
       ret      

Program:AddMem(byref):int (FullOpts):
       mov      eax, dword ptr [rdi]
       lea      ecx, [rax+rax]
       add      eax, ecx
       ret      

Program:SubReg(int):int (FullOpts):
       xor      eax, eax
       sub      eax, edi
       ret      

Program:SubMem(byref):int (FullOpts):
       mov      eax, dword ptr [rdi]
       mov      ecx, eax
       sub      ecx, eax
       sub      ecx, eax
       mov      eax, ecx
       ret      

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIhelp wanted[up-for-grabs] Good issue for external contributorsoptimization

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions