-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Closed
Copy link
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is mergedtenet-performancePerformance related issuePerformance related issue
Milestone
Description
JIT currently elides bounds check for for (int i = 0; i < arr.Length; i++) loops.
When ClearBase is inlined with the given function arguments it is equivalent to exactly that, however the bounds check is not removed when targeting windows. See: https://godbolt.org/z/PMx8oPrM9. With int[] the redundant check is gone.
static void Clear(Span<int> arr)
{
ClearBase(arr, arr.Length);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void ClearBase(Span<int> arr, int len)
{
for (int i = 0; i < len; i++)
{
arr[i] = 0;
}
}Program:Clear(System.Span`1[int]) (FullOpts):
sub rsp, 40
mov rax, bword ptr [rcx]
mov ecx, dword ptr [rcx+0x08]
mov edx, ecx
xor r8d, r8d
test ecx, ecx
jle SHORT G_M46351_IG04
align [13 bytes for IG03]
G_M46351_IG03: ;; offset=0x0020
cmp r8d, edx
jae SHORT G_M46351_IG05
xor r10d, r10d
mov dword ptr [rax+4*r8], r10d
inc r8d
cmp r8d, ecx
jl SHORT G_M46351_IG03
G_M46351_IG04: ;; offset=0x0034
add rsp, 40
ret
G_M46351_IG05: ;; offset=0x0039
call CORINFO_HELP_RNGCHKFAIL
int3 Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is mergedtenet-performancePerformance related issuePerformance related issue