JIT: Strength reduction only done with native sized int
- 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
Assessment
This issue has not been assessed yet.