Eliminate ToArray bounds checks#81001
Merged
Merged
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
|
xtqqczze
commented
Jan 22, 2023
RangeIterator.ToArray bounds checkRangeIterator.ToArray bounds check
RangeIterator.ToArray bounds checkRangeIterator.ToArray() bounds check
RangeIterator.ToArray() bounds checkRangeIterator.ToArray bounds check
RangeIterator.ToArray bounds checkToArray bounds checks
stephentoub
approved these changes
Jan 22, 2023
Contributor
Author
|
@stephentoub Found some more instances of the same. |
Comment on lines
+257
to
260
| for (int i = 0, curIdx = _minIndexInclusive; i < array.Length; ++i, ++curIdx) | ||
| { | ||
| array[i] = _source[curIdx]; | ||
| } |
Contributor
There was a problem hiding this comment.
Suggested change
| 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.
mdh1418
pushed a commit
to mdh1418/runtime
that referenced
this pull request
Jan 24, 2023
* Remove `RangeIterator.ToArray` bounds check dotnet#80633 (comment) * Eliminate additional `ToArray` bounds checks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See #80633 (comment):
cc: @stephentoub