Uh oh!
There was an error while loading. Please reload this page.
RyuJIT: Don't convert GT/LE to EQ/NE for "ARR_LEN cmp 0" - #35758
Closed
EgorBo wants to merge 1 commit into
Closed
Conversation
benaadams
commented
May 2, 2020
Member
publicstaticvoidFoo1(Span<int>array){if((uint)array.Length>0)array[0]=42;}publicstaticvoidFoo2(Span<int>array){if(0<(uint)array.Length)// same condition, different orderarray[0]=42;}C.Foo1(System.Span`1<Int32>) L0000: pushebp L0001: movebp,esp L0003: moveax,[ebp+0xc] L0006: testeax,eax L0008: jz L0018 L000a: cmpeax,0x0 L000d: jbe L001c L000f: moveax,[ebp+0x8] L0012: mov dword [eax],0x2a L0018: popebp L0019: ret0x8 L001c: call0x62022680 L0021: int3C.Foo2(System.Span`1<Int32>) L0000: moveax,[esp+0x8] L0004: testeax,eax L0006: jz L0012 L0008: moveax,[esp+0x4] L000c: mov dword [eax],0x2a L0012: ret0x8 |
| // and (x GT_LE.unsigned 0) into (x GT_EQ 0). The later case is rare, it sometimes | ||
| // occurs as a result of branch inversion. | ||
| // NOTE: keep it as it is for Array.Length op1 since GT_NE/GT_EQ operators are | ||
| // not bounds check elimination friendly yet. |
Contributor
There was a problem hiding this comment.
Do you know how hard it is to make it friendly?
As I see we use
runtime/src/coreclr/src/jit/gentree.h
Line 1563 in 8527a99
EQ/NE there, should we add them?EgorBo
commented
Sep 10, 2020
MemberAuthor
As far as I understand it's already handled in #40180 |
nathan-moore
commented
Sep 13, 2020
Contributor
I checked, it indeed is :). Should also handle the span case. |
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 freeto 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.
RyuJIT converts
(uint)x > 0tox != 0(same for<=) but I suggest we keep it as it is for things like(uint)array.Length > 0since!=and==operators are not bound checks elimination friendly, e.g.:Before my changes
^ As you can see, bound checks are removed only for "unnatural" (IMO) condition in
Foo3That's why we have this "unnatural" conditions in String.IsNullOrEmpty and other places.
After my changes