-
Notifications
You must be signed in to change notification settings - Fork 5k
JIT: Transform SELECT(relop, 1/0, 0/1) to relop #81880
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: Transform SELECT(relop, 1/0, 0/1) to relop #81880
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak Issue DetailsFix #81479 FWIW, initially I generalized this to handle any power of two via We could also do this directly in if-conversion, though then we wouldn't get potential future SELECTs created in different places.
|
This should help Roslyn/F# for this case: dotnet/roslyn#61483 |
src/coreclr/jit/lower.cpp
Outdated
if (select->TypeIs(TYP_LONG)) | ||
{ | ||
GenTree* cast = comp->gtNewCastNode(TYP_LONG, newNode, false, TYP_LONG); | ||
BlockRange().InsertAfter(newNode, cast); |
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.
Why cast here is needed? if we know that we return either 0 or 1 - can we leave it TYP_INT (sort of legal after lowering)
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.
Hmm, indeed it looks like compare nodes support being TYP_LONG
typed in codegen, so I can just retype it. Will fix
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.
New diffs, a bit better now, but I guess it was rare that we needed this cast
Possible regression in |
Possible improvements: |
Fix #81479
Initially I generalized this to handle any power of two via
LSH(cond, shift)
. Like GCC and Clang do here: https://godbolt.org/z/hxPf3Ka8eHowever, it had worse performance than a cmov from my measurements (around 20% slower). It would use one less register in many situations though.
We could also do this directly in if-conversion, though then we wouldn't get potential future SELECTs created in different places.
Example:
Before:
After #81267:
After #81267 + this PR: