-
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
JIT: optimize "o is byte[]" casts #75991
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsFollow up to #75816 that optimized such checks for exact classes. Array of integers, bytes, etc are special and can be casted to their signed/unsigned equivalents, so let's expand bool IsByteArray(IEnumerable o) => o is byte[]; Current codegen: ; Method Tests:IsByteArray(System.Collections.IEnumerable):bool:this
G_M51298_IG01:
4883EC28 sub rsp, 40
G_M51298_IG02:
48B920FD447CFE7F0000 mov rcx, 0x7FFE7C44FD20 ; ubyte[]
FF155472FBFF call [CORINFO_HELP_ISINSTANCEOFARRAY]
4885C0 test rax, rax
0F95C0 setne al
0FB6C0 movzx rax, al
G_M51298_IG03:
4883C428 add rsp, 40
C3 ret
; Total bytes of code: 34 New codegen: ; Method Tests:IsByteArray(System.Collections.IEnumerable):bool:this
G_M51298_IG01:
4883EC28 sub rsp, 40
G_M51298_IG02:
488BC2 mov rax, rdx
4885C0 test rax, rax
741F je SHORT G_M51298_IG05G_M51298_IG03:
48B920FDB976FE7F0000 mov rcx, 0x7FFE76B9FD20 ; ubyte[]
483908 cmp qword ptr [rax], rcx
7410 je SHORT G_M51298_IG05
G_M51298_IG04:
48B920FDB976FE7F0000 mov rcx, 0x7FFE76B9FD20 ; ubyte[]
FF153D72FBFF call [CORINFO_HELP_ISINSTANCEOFARRAY]
G_M51298_IG05:
4885C0 test rax, rax
0F95C0 setne al
0FB6C0 movzx rax, al
G_M51298_IG06:
4883C428 add rsp, 40
C3 ret
; Total bytes of code: 57
|
You can make similar argument for all The problem with the |
@jkotas Thanks, also realized that when I was looking at this.
other primitives like |
Nope. This prints true:
|
Ah, totally forgot about the Enums it makes it way more difficult then 🙁 |
Technically still can be allowed for some primitives where we can't use Enums: |
Follow up to #75816 that optimized such checks for exact classes.
Array of integers, bytes, etc are special and can be casted to their signed/unsigned equivalents, so let's expand
isinst
for them to handle at least one of the cases as a fast path. Presumably, it's a rare case when e.g.obj is int[]
andobj
isuint[]
. In theory we can check for both without the fallback but that will require a new JIT-EE API with extra complexity while I think the declaration type is the most likely target.Current codegen:
New codegen: