dotnet / dotnet/runtime

JIT: Strength reduction only done with native sized int

Open
#122,158 18 comments 0 reactions 0 assignees View on GitHub
area-CodeGen-coreclr
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

Only when the iteration variable is a native sized int does it do strength reduction.
```cs
// 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;
}
```

```assembly
G_M63938_IG04: ;; offset=0x000E
add eax, dword ptr [rsi]
add rsi, 4
dec rcx
jne SHORT G_M63938_IG04
```
vs
```assembly
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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.