Repository navigation
JIT: Optimize constant range tests - #93521
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue Detailsvoid Test(char c)
{
if ((c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z'))
Console.WriteLine("a-zA-Z");
}Current codegen: ; Assembly listing for method Prog:Test(ushort):this (FullOpts)
movzx rcx, dx
cmp ecx, 97
jl SHORT G_M56518_IG04
cmp ecx, 122
jle SHORT G_M56518_IG05
G_M56518_IG04:
cmp ecx, 65
jl SHORT G_M56518_IG07
cmp ecx, 90
jg SHORT G_M56518_IG07
G_M56518_IG05:
mov rcx, 0x13A00208D40 ; 'a-zA-Z'
tail.jmp [System.Console:WriteLine(System.String)]
G_M56518_IG07:
ret
; Total bytes of code 40New codegen: ; Assembly listing for method Prog:Test(ushort):this (FullOpts)
movzx rcx, dx
mov eax, ecx
sub eax, 97
cmp eax, 25
jbe SHORT G_M56518_IG04
sub ecx, 65
cmp ecx, 25
ja SHORT G_M56518_IG06
G_M56518_IG04:
mov rcx, 0x1E200008D40 ; 'a-zA-Z'
G_M56518_IG05:
tail.jmp [System.Console:WriteLine(System.String)]
G_M56518_IG06:
ret
; Total bytes of code 38Not a big size win (sometimes even a size regression actually), but less branches (takes PGO into account). Alternative patterns:
|
|
/azp list |
This comment was marked as resolved.
This comment was marked as resolved.
|
/azp run runtime-coreclr outerloop, runtime-coreclr jitstress, Fuzzlyn |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
@AndyAyersMS @jakobbotsch @dotnet/jit-contrib PTAL, diffs are not too big because we only save 2 bytes on average, but we get rid of a branch, so, hopefully, it will be noticeable. Outerloop/Jitstress/fuzzlyn pass. Can be separately extended to:
Motivated by https://github.com/ricomariani/wrath-othello benchmark. |
AndyAyersMS
left a comment
There was a problem hiding this comment.
Nice.
I think it would be a bit more challenging to fit this sort of thing into RBO because it modifies the upper branch and not the lower one. But still worth doing someday.
|
Failure is #93527 |
|
I assume it isn't worth the effort to detect+apply the bit fiddling to map lower to upper case (masking 1 bit) and then check a single range, like in the new ascii helpers? |
I am not sure I understood, can you explaind it via code? 🙂 |
Current codegen:
New codegen:
Not a big size win (sometimes even a size regression actually), but less branches (takes PGO into account).
Alternative patterns:
c < 'a' || c > 'z'c is >= 'a' and <= 'z' or >= 'A' and <= 'Z'