Skip to content

JIT: Strength reduction only done with native sized int #122158

@BoyBaykiller

Description

@BoyBaykiller

Only when the iteration variable is a native sized int does it do strength reduction.

// https://godbolt.org/z/hdTeGEeE1
int TestNint(int* data, int count)
{
    int sum = 0;
    for (nint i = 0; i < count; i++)
    {
        sum += data[i];
    }

    return sum;
}

int TestInt(int* data, int count)
{
    int sum = 0;
    for (int i = 0; i < count; i++)
    {
        sum += data[i];
    }

    return sum;
}
G_M63938_IG04:  ;; offset=0x000E
       add      eax, dword ptr [rsi]
       add      rsi, 4
       dec      rcx
       jne      SHORT G_M63938_IG04

vs

G_M29388_IG03:  ;; offset=0x000C
       movsxd   rdi, ecx
       add      eax, dword ptr [rsi+4*rdi]
       inc      ecx
       cmp      ecx, edx
       jl       SHORT G_M29388_IG03

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