Repository navigation
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issue
Milestone
Description
Here's an example similar to #9421 that came up in some span conversion efforts in CoreFX:
static ReadOnlySpan<char> Slice(ReadOnlySpan<char> s)
{
ReadOnlySpan<char> result = s.Slice(s.Length & ~3);
return result;
}Current asm:
G_M7513_IG01:
4883EC28 sub rsp, 40
G_M7513_IG02:
488B02 mov rax, bword ptr [rdx]
8B5208 mov edx, dword ptr [rdx+8]
448BC2 mov r8d, edx
4183E0FC and r8d, -4
443BC2 cmp r8d, edx
7718 ja SHORT G_M7513_IG05
G_M7513_IG03:
412BD0 sub edx, r8d
4D63C0 movsxd r8, r8d
4A8D0440 lea rax, bword ptr [rax+2*r8]
488901 mov bword ptr [rcx], rax
895108 mov dword ptr [rcx+8], edx
488BC1 mov rax, rcx
G_M7513_IG04:
4883C428 add rsp, 40
C3 ret
G_M7513_IG05:
E89DF34A5E call ThrowHelper:ThrowArgumentOutOfRangeException()
CC int3Slicing a span with lengths specified by suitable functions of the span length should allow the range check to be optimized away (suitable meaning mods, &, guarded subtracts, etc). This should be a very common case as presumably users are almost always looking at the original length when figuring out slices and out of bounds slicing will be rare.
Or, for an even more blatant example:
static ReadOnlySpan<char> Slice(ReadOnlySpan<char> s)
{
ReadOnlySpan<char> result = s.Slice(s.Length);
return result;
}current asm is kinda sad:
G_M7513_IG01:
4883EC28 sub rsp, 40
G_M7513_IG02:
488B02 mov rax, bword ptr [rdx]
8B5208 mov edx, dword ptr [rdx+8]
448BC2 mov r8d, edx
413BD0 cmp edx, r8d
771B ja SHORT G_M7513_IG05
G_M7513_IG03:
418BD0 mov edx, r8d
412BD0 sub edx, r8d
4D63C0 movsxd r8, r8d
4A8D0440 lea rax, bword ptr [rax+2*r8]
488901 mov bword ptr [rcx], rax
895108 mov dword ptr [rcx+8], edx
488BC1 mov rax, rcx
G_M7513_IG04:
4883C428 add rsp, 40
C3 ret
G_M7513_IG05:
E89EF33C5F call ThrowHelper:ThrowArgumentOutOfRangeException()
CC int3cc @dotnet/jit-contrib
Reacted by nietras, Adam and Stefan
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issue
Activity
AndyAyersMS commentedon Dec 12, 2017
Guessing that part of the problem is that struct promotion doesn't clear the
GTF_GLOBAL_REFflags in ancestor trees, leaving us with things like:AndyAyersMS commentedon Dec 13, 2017
Looks like we can optimize even when those flags are set. Here are some possibly useful changes in value numbering: master...AndyAyersMS:ValueNumCompareSubIdentities
Leads to a small handful of good diffs in jit-diffs. Won't have time to push these further now as I'm off on vacation for a few weeks.
cc @briansull
briansull commentedon Jan 3, 2018
@AndyAyersMS The additional ValueNumbering optimizations mentioned, look good.