-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Extend the "skip-test" optimization to all instructions that modify the #120876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@dotnet-policy-service agree |
|
@kg, PTAL. |
|
This LGTM but will need to pass CI before it can be merged. Let me know if you need help figuring out why the runtime tests lanes are red. |
|
@Lotendan to elaborate on the above, technically, this code: popcnt edi, edi
jg SHORT G_M000_IG04is an invalid replacement for popcnt edi, edi
test edi, edi
jg SHORT G_M000_IG04because the latter sets SF explicitly before checking it with In the case of If you instead introduce an assertion (see popcnt edi, edi
jne SHORT G_M000_IG04 |
|
Thank you for the hint about the assertions. Very helpful as I'm totally new to this code base.
|
|
If you add the assertion, you don't have to worry about removing the This is actually already handled for explicit calls to I believe all you need to do is duplicate this range assertion: runtime/src/coreclr/jit/assertionprop.cpp Lines 306 to 314 in 228a12c
for |
|
@Lotendan I gave this a closer look today, and I have a couple of corrections
runtime/src/coreclr/jit/morph.cpp Lines 9226 to 9239 in a2b94d3
static void M2(int value)
{
if (int.PopCount(value) < 0)
throw null!;
}which already compiles to just C:M2(int) (FullOpts):
ret because JIT is already seeing that the value can't be negative. So, if you were to add the missing |
1e73a3e to
10972b8
Compare
|
Your intuition was good and gave me the right tools to progress on this bugfix. public static void M1(int value)
{
if (int.PopCount(value) > 0)
throw null!;
}
public static void M2(uint value)
{
if (uint.PopCount(value) > 0)
throw null!;
}
public static void M3(int value)
{
if (Popcnt.PopCount((uint) value) > 0)
throw null!;
}And they all end up as: IN0001: 000003 popcnt ecx, ecx
IN0002: 000007 jne SHORT G_M1455_IG04Replacing with IN0001: 000003 lzcnt ecx, ecx
IN0002: 000007 jne SHORT G_M1455_IG04Same for IN0001: 000003 tzcnt ecx, ecx
IN0002: 000007 jne SHORT G_M28251_IG04 |
|
The new changes LGTM. Thanks for providing guidance @saucecontrol , I appreciate having someone who knows the JIT well chime in. |
|
@kg what are the next steps then to merge this PR? :) |
|
Now that checks have passed I'm going to get the OK to merge it since I'm new to the JIT. I'm not sure how long that will take, thanks for your patience! |
|
@dotnet/jit-contrib PTAL |
10972b8 to
1c8f78b
Compare
1c8f78b to
7d0b43a
Compare
|
Thanks, I have applied the suggestions. |
AndyAyersMS
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this improvement.
|
@Lotendan can you update this branch and re-run CI? |
7d0b43a to
60eb31a
Compare
|
Rebased this branch on the main branch :) |
|
@Lotendan I think we are good to merge this! You can do the honors if you'd like! Thank you for this contribution! |
|
Thanks @adamperlin ! I don’t have merge permissions in this repo, so feel free to merge it when convenient ;) |
Extend the "skip-test" optimization to all instructions that modify the same flags as "TEST" x86 instruction
Originally wanted to only cover the "POPCNT" case, but actually we can go further than that and cover more instructions.
Fixes #118811
Using the following code:
This fix reduces this assembly:
to this assembly:
Note: this is not exactly as was intended in the issue, where a
jnewas expected. But that should be good enough.Note2: this does not affect
tnzcntorlzcntinstructions as these instructions do not modify the flags.