Repository navigation
JIT: Use inline label for fall-though blocks in codegen to give peephole opts a better chance - #128536
JIT: Use inline label for fall-though blocks in codegen to give peephole opts a better chance#128536BoyBaykiller wants to merge 5 commits into
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
…== 0)' suggested by LLM
|
that is definitely not the right fix, it has to be fixed in RBO, @AndyAyersMS recently added a similar optimization where dominated relop effectively makes dominating one redundant. |
|
Which branch are you suggesting RBO to remove? static bool MissedReuseCmp(byte ch)
{
if (ch <= 32)
{
if (ch != 32)
{
Console.WriteLine("Hi!");
return false;
}
return true;
}
return false;
}Even if it was fixable in RBO (which I dont think so?) this is useful either way. |
It should be fixed in RBO with jump-threading actually. Console.WriteLine("Hi!"); is accessible with just if (ch < 32) |
|
This looks better but still requires two compares: static bool MissedReuseCmpIdeal(byte ch)
{
if (ch < 32)
{
Console.WriteLine("Hi!");
}
else if (ch == 32)
{
return true;
}
return false;
}G_M36236_IG02: ;; offset=0x0004
movzx rax, cl
cmp eax, 32
jg SHORT G_M36236_IG06
;; size=8 bbWeight=1 PerfScore 1.50
G_M36236_IG03: ;; offset=0x000C
cmp eax, 32 ; <- redundant, re-use flag
jne SHORT G_M36236_IG05
mov eax, 1Which this PR removes. Actually to handle this we need to a peehole variant of |
* handle empty IGF_EXTENSION * small things
|
Closing, because even though the diffs seem good, this approach misses cases and has the downside of interfering with GC info. Here is an example this PR misses, I would like to handle: static bool Missed(bool cond, int a, int b)
{
if (a <= b)
{
return a != b && cond;
}
return true;
}G_M60931_IG02:
cmp edx, r8d
jle SHORT G_M60931_IG05
G_M60931_IG03:
mov eax, 1
G_M60931_IG04:
ret
G_M60931_IG05:
cmp edx, r8d ; <- we don't remove this because it's not right after G_M60931_IG02
setne al
movzx rax, al
movzx rcx, cl
and eax, ecx
G_M60931_IG06:
ret
I think in order to properly handle this we need a good representation of CPU flags and still have a control flow graph, linking #74867 |
…c vars) (#128811) This random method (and other) tells us at that `igData` points to after the gc vars. https://github.com/dotnet/runtime/blob/f2d5042ceaea5642bac6bde8a1a5765afcbf2ef4/src/coreclr/jit/emit.h#L352-L360 More specifically it points to "addr of instruction descriptors". However the corresponding debug-only `igDataSize` was being assigned `gs` which is the size of the entire IG (including gc vars). It should use code size (`sz`) instead. Fixes this assert I was hitting in #128536: https://github.com/dotnet/runtime/blob/f2d5042ceaea5642bac6bde8a1a5765afcbf2ef4/src/coreclr/jit/emit.cpp#L10081
Example:
G_M11242_IG01: ;; offset=0x0000 sub rsp, 40 ;; size=4 bbWeight=1 PerfScore 0.25 G_M11242_IG02: ;; offset=0x0004 cmp ecx, edx jl SHORT G_M11242_IG05 ;; size=4 bbWeight=1 PerfScore 1.25 G_M11242_IG03: ;; offset=0x0008 - cmp ecx, edx sete al movzx rax, al - ;; size=8 bbWeight=0.50 PerfScore 0.50 + ;; size=6 bbWeight=0.50 PerfScore 0.38 G_M11242_IG04: ;; offset=0x000E add rsp, 40 ret ;; size=5 bbWeight=0.50 PerfScore 0.62 G_M11242_IG05: ;; offset=0x0013 mov rcx, 0x2BEC8714F98 ; 'Hi!' call [System.Console:WriteLine(System.String)] xor eax, eax ;; size=18 bbWeight=0.50 PerfScore 1.75 G_M11242_IG06: ;; offset=0x0025 add rsp, 40 ret ;; size=5 bbWeight=0.50 PerfScore 0.62Fix #128535