-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
JIT: Don't emit some unnecessary tests #38586
Conversation
@nathan-moore thanks for this PR. I actually would have expected a wider range of diffs -- eg an earlier prototype from @benaadams saw more cases. Would be good to understand what's different between that version and yours. @kunalspathak has created a tool in jit-utils to scan for patterns in asm, perhaps we could run it and see if there are more cases like this to catch? Can you also check for extended IGs as in Kunal's PR? Also can you double-check the examples from #32389? Here's a simple version you can try: using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
class X
{
[MethodImpl(MethodImplOptions.NoInlining)]
static long Foo(long x)
{
long lengthToExamine = x - Vector256<byte>.Count;
if (lengthToExamine != 0)
{
return lengthToExamine;
}
else
{
return 0;
}
}
public static int Main()
{
return (int) Foo(0);
}
} cc @dotnet/jit-contrib |
No diffs in your example @AndyAyersMS , since the add turns into a lea. Ultimately, the lower diffs are due to the possibility of integer over/underflow, which makes the handling here have to be pretty conservative. If there's some sort of overflow analysis I can consume, we could probably get pretty close to a 4.5k diff that assumes no overflow, which is similar to what ben's prototype did. #6794 might also help recover some (most?) of these missed optimizations since this pr handles the common dec/inc case. |
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.
LGTM, I would like to have that change in before the feature lock, thoughts @dotnet/jit-contrib ?
With a clean jit-stress run I am going to merge it later today If there are no objections. |
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.
LGTM. Thanks!
Don't emit compares to 0 if the previous instruction has set the appropriate flags.
Fixes #10742
Diffs: