-
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
Unroll SequenceEqual for u8 literals #82474
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak Issue Detailsbool IsValue(ReadOnlySpan<byte> a) => a.SequenceEqual("value"u8); Current codegen:; Method P:IsValue(System.ReadOnlySpan`1[ubyte]):bool:this
G_M29601_IG01:
sub rsp, 40
G_M29601_IG02:
mov r8, 0xD1FFAB1E
mov rcx, bword ptr [rdx]
mov edx, dword ptr [rdx+08H]
mov bword ptr [rsp+20H], r8
cmp edx, 5
jne SHORT G_M29601_IG04
G_M29601_IG03:
mov edx, 5
mov r8, rdx
mov rdx, bword ptr [rsp+20H]
call [System.SpanHelpers:SequenceEqual(byref,byref,ulong):bool]
jmp SHORT G_M29601_IG05
G_M29601_IG04:
xor eax, eax
G_M29601_IG05:
add rsp, 40
ret
; Total bytes of code: 58
Should be unrolled similar to UTF-16: bool IsValue(ReadOnlySpan<char> a) => a.SequenceEqual("value"); Current codegen:; Method P:IsValue(System.ReadOnlySpan`1[ushort]):bool:this
G_M10905_IG01:
G_M10905_IG02:
mov rax, bword ptr [rdx]
cmp dword ptr [rdx+08H], 5
jne SHORT G_M10905_IG04
G_M10905_IG03:
mov rdx, 0x75006C00610076
xor rdx, qword ptr [rax]
mov eax, dword ptr [rax+06H]
xor eax, 0x650075
or rax, rdx
sete al
movzx rax, al
jmp SHORT G_M10905_IG05
G_M10905_IG04:
xor eax, eax
G_M10905_IG05:
ret
; Total bytes of code: 44 MotivationTo clean up various places like:
|
I thought we already did this :( Thanks for opening the issue. We don't do any such handling for bytes today, just chars? |
Yep, chars only at the moment. RVA didn't fit well into that importer-level optimization, but I have a quick prototype to do this expansion later in ValueNumbering (or Early Prop). We also can then expand it for other patterns like runtime/src/libraries/System.Private.CoreLib/src/System/Boolean.cs Lines 113 to 115 in d454374
|
Closed via #83945 bool IsValue(ReadOnlySpan<byte> a) => a.SequenceEqual("value"u8); ; Method Prog:IsValue(System.ReadOnlySpan`1[ubyte]):bool:this
G_M18139_IG01:
sub rsp, 40
;; size=4 bbWeight=1 PerfScore 0.25
G_M18139_IG02:
mov rax, 0xD1FFAB1E ; data for <PrivateImplementationDetails>:2AC3E771679DFE9EC82B8748F6F7718F3AD0E4EAAFABC9F68F4BC25187A5F230
mov rcx, bword ptr [rdx]
mov edx, dword ptr [rdx+08H]
cmp edx, 5
jne SHORT G_M18139_IG04
;; size=21 bbWeight=1 PerfScore 5.50
G_M18139_IG03:
mov edx, dword ptr [rcx]
mov r8d, dword ptr [rax]
mov ecx, dword ptr [rcx+01H]
mov eax, dword ptr [rax+01H]
xor edx, r8d
xor eax, ecx
or eax, edx
sete al
movzx rax, al
jmp SHORT G_M18139_IG05
;; size=26 bbWeight=0.50 PerfScore 6.00
G_M18139_IG04:
xor eax, eax
;; size=2 bbWeight=0.50 PerfScore 0.12
G_M18139_IG05:
add rsp, 40
ret
;; size=5 bbWeight=1 PerfScore 1.25
; Total bytes of code: 58 |
@EgorBo for Is it possible to have this codegen here too? I.e. avoid the memory loads for the constant parts, and use only constant values. |
A bit more complicated fix since I'll have to do that in an earlier phase. I just wanted to land a quick fix and see impact from it, so far not much |
Should be unrolled similar to UTF-16:
Motivation
To clean up various places like:
Work items
The text was updated successfully, but these errors were encountered: