-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eliminate ToArray
bounds checks
#81001
Conversation
Tagging subscribers to this area: @dotnet/area-system-linq Issue DetailsSee #80633 (comment): // crossgen2 8.0.0-alpha.1.23061.99+71bb0d481086b8b8a89a99a17ec80a861f32dc5d
C:ToArray_Base():int[]:this:
; Emitting BLENDED_CODE for X64 CPU with SSE2 - Unix
push rbp
push rbx
push rax
lea rbp, [rsp+10H]
;; size=8 bbWeight=1 PerfScore 3.50
mov eax, dword ptr [rdi+0CH]
mov ebx, dword ptr [rdi+08H]
sub eax, ebx
movsxd rdi, eax
call [CORINFO_HELP_READYTORUN_NEWARR_1]
xor edi, edi
mov esi, dword ptr [rax+08H]
test esi, esi
je SHORT G_M50617_IG04
;; size=26 bbWeight=1 PerfScore 11.00
G_M50617_IG03:
cmp edi, esi
jae SHORT G_M50617_IG05
mov edx, edi
mov dword ptr [rax+4*rdx+10H], ebx
inc ebx
inc edi
cmp esi, edi
jne SHORT G_M50617_IG03
;; size=18 bbWeight=4 PerfScore 17.00
G_M50617_IG04:
add rsp, 8
pop rbx
pop rbp
ret
;; size=7 bbWeight=1 PerfScore 2.25
G_M50617_IG05:
call [CORINFO_HELP_RNGCHKFAIL]
int3
;; size=7 bbWeight=0 PerfScore 0.00
C:ToArray_Diff():int[]:this:
; Emitting BLENDED_CODE for X64 CPU with SSE2 - Unix
push rbp
push rbx
push rax
lea rbp, [rsp+10H]
;; size=8 bbWeight=1 PerfScore 3.50
mov eax, dword ptr [rdi+0CH]
mov ebx, dword ptr [rdi+08H]
sub eax, ebx
movsxd rdi, eax
call [CORINFO_HELP_READYTORUN_NEWARR_1]
xor edi, edi
mov esi, dword ptr [rax+08H]
test esi, esi
jle SHORT G_M19969_IG04
;; size=26 bbWeight=1 PerfScore 11.00
G_M19969_IG03:
mov edx, edi
mov dword ptr [rax+4*rdx+10H], ebx
inc ebx
inc edi
cmp esi, edi
jg SHORT G_M19969_IG03
;; size=14 bbWeight=4 PerfScore 12.00
G_M19969_IG04:
add rsp, 8
pop rbx
pop rbp
ret
;; size=7 bbWeight=1 PerfScore 2.25
|
RangeIterator.ToArray
bounds checkRangeIterator.ToArray
bounds check
RangeIterator.ToArray
bounds checkRangeIterator.ToArray()
bounds check
RangeIterator.ToArray()
bounds checkRangeIterator.ToArray
bounds check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
RangeIterator.ToArray
bounds checkToArray
bounds checks
@stephentoub Found some more instances of the same. |
for (int i = 0, curIdx = _minIndexInclusive; i < array.Length; ++i, ++curIdx) | ||
{ | ||
array[i] = _source[curIdx]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (int i = 0, curIdx = _minIndexInclusive; i < array.Length; ++i, ++curIdx) | |
{ | |
array[i] = _source[curIdx]; | |
} | |
int minIndexInclusive = _minIndexInclusive; | |
for (int i = 0; i < array.Length; ++i) | |
{ | |
array[i] = _source[i + minIndexInclusive]; | |
} |
This feels a bit simpler to me.
* Remove `RangeIterator.ToArray` bounds check dotnet#80633 (comment) * Eliminate additional `ToArray` bounds checks
See #80633 (comment):
cc: @stephentoub