Closed kunalspathak closed 3 years ago
@dotnet/jit-contrib
Would also be interesting to screen for cases where we have a non-move writing a register, followed by a test, followed by a jump.
In particular
lea; test; jcc
I can add more patterns but I just restricted myself to handful of them for time sake. lea
doesn't affect any flag, so wondering how can lea
screening help? We won't be able to optimize test
anyway in that case, right?
how can
lea
screening help?
If we can find places where we're forming lea
upstream of a jump we might want to reconsider and use a flag-setting instruction instead, as we may be happier overall since we can then omit the test
.
For instance, if we have lea; test; jmp
we might be better off with add; jump
.
For instance, if we have
lea; test; jmp
we might be better off withadd; jump
.
So although lea
is faster than add
, you are thinking that elimination of extra test
will offset the degradation?
Hard to say. Both lea; test; jcc
and add; jcc
will benefit from macro-fusion. But I suspect the latter is faster, provided we're only adding one thing in the lea
.
Just found 19 hits of lea
like these:
; Assembly listing for method System.MathF:Round(float):float
[0053] lea ecx, [rsi+rsi]
[0054] test ecx, ecx
[0055] jne SHORT G_M2148_IG05
Added
FindRedundantTest()
method that looks for redundanttest
instruction in the dasm files. I have scoped it to limited jump instructions, but can be extended in the future. Used in https://github.com/dotnet/runtime/issues/53053.