Repository navigation
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone
Description
bool IsValue(ReadOnlySpan<byte> a) => a.SequenceEqual("value"u8);; Method P:IsValue(System.ReadOnlySpan`1[ubyte]):bool:this
sub rsp, 40
mov r8, 0xD1FFAB1E ;; address of RVA field
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
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
add rsp, 40
ret
; Total bytes of code: 58
Should be unrolled similar to UTF-16:
bool IsValue(ReadOnlySpan<char> a) => a.SequenceEqual("value");; Method P:IsValue(System.ReadOnlySpan`1[ushort]):bool:this
mov rax, bword ptr [rdx]
cmp dword ptr [rdx+08H], 5
jne SHORT G_M10905_IG04
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: 44Motivation
To clean up various places like:
- JsonSerializer.Read.HandleMetadata.cs
- aspnetcore's HttpHeaders.Generated.cs
- ^ similar to that in runtime: HeaderDescriptor.cs - this currently picks a candidate and then does non-optimized comparison while it could do comparison against u8 literal in each case
- Should optimize TE benchmarks as well e.g. here BenchmarkApplication.cs
Work items
- SequenceEqual
- OrdinalIgnoreCase
- StartsWith
Reacted by Ben {chmark} Adams, Jasper, OmariO, neon-sunset and Miha Zupan
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Activity
stephentoub commentedon Feb 22, 2023
I thought we already did this :( Thanks for opening the issue. We don't do any such handling for bytes today, just chars?
EgorBo commentedon Feb 22, 2023
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
"false"u8.CopyTo(span)runtime/src/libraries/System.Private.CoreLib/src/System/Boolean.cs
Lines 113 to 115 in d454374
EgorBo commentedon Apr 1, 2023
Closed via #83945
gfoidl commentedon Apr 2, 2023
@EgorBo for
charthexoris done against two constants, saving two memory loads. The JIT is able to do this when written manually.Is it possible to have this codegen here too? I.e. avoid the memory loads for the constant parts, and use only constant values.
EgorBo commentedon Apr 2, 2023
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