Bound checks not elided in loop
Open
area-CodeGen-coreclr
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
Similar idea as #121262, but where the check is part of the loop condition
https://godbolt.org/z/Yf1nd4cof
```c#
public static int Sum1(ReadOnlySpan input)
{
int sum = 0;
for (int i = 0; (uint)(i + 2) < (uint)input.Length; i += 3)
{
sum += input[i] + input[i + 1] + input[i + 2]; // All 3 accesses are checked
}
return sum;
}
```
vs
```c#
public static int Sum2(ReadOnlySpan input)
{
int sum = 0;
for (int i = 0; i < input.Length && (uint)(i + 2) < (uint)input.Length; i += 3)
{
sum += input[i] + input[i + 1] + input[i + 2]; // No checks
}
return sum;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.