-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
"==0" optimization in Boolean logic #13573 #49548
Conversation
Just curious, where is the hit in XElement.AttributesEqual? Is it somehow collapsing the distinct checks of name and value (both references)? runtime/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XElement.cs Lines 1918 to 1933 in ecc354a
|
Transforming I wonder if this optimization could actually cause regressions in already hand-optimized code by introducing additional register pressure and memory accesses? For example transforming |
Working on other failing case. Will look into this later.
|
Thanks for the good catch. I meant
We did this in order to reduce branching cost. |
@danmoseley It is the last statement that is optimized.
Before optimization:
After optimization:
|
@AndyAyersMS all pri 0 tests passed. Please review this PR. |
Transforming |
Are there test cases in the CoreCLR pri-1 tests that hit all the cases you intend to optimize? If not, can you add a unit test (or multiple) that diffs will show this affecting? |
It is boolean optimization, so the values that are compared to is either 0 or 1. |
/azp list |
/azp run runtime-coreclr outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp runtime-coreclr jitstress |
This comment has been minimized.
This comment has been minimized.
/azp run runtime-coreclr jitstress |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
Left you some notes....
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.
left a few notes.
/azp run runtime-coreclr outerloop |
/azp run runtime-coreclr jitstress |
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
Azure Pipelines successfully started running 1 pipeline(s). |
CI is complaining about the C/C++ formatting |
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.
It seems like a lot of code change for very few diffs. Why are there so few diffs?
Levi suggested handling cases like (a > 0) && (b > 0)
. Future work?
The optimization doesn't handle cases like bool b = a == 0 && b == 0 && c == 0
because the last block is a GT_ASG
instead of GT_RETURN
(for example). Future work?
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.
More comments.
Also, at some point, and after all changes are approved and final, make sure to run outerloop and jitstress pipelines.
Is it because I had many commits?
He suggested
This case was not handled. Will inlcude this case in the new issue together with |
@BruceForstall @dotnet/jit-contrib I addressed BruceForstall's code review feedback. PTAL. |
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.
Think this is getting close.
…and added test cases
@AndyAyersMS @BruceForstall PTAL. |
/azp run runtime-coreclr outerloop |
/azp run runtime-coreclr jitstress |
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
Azure Pipelines successfully started running 1 pipeline(s). |
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.
I left a couple comments, but nothing blocking.
@BruceForstall @dotnet/jit-contrib PTAL. I incorporated Bruce's code review feedback. |
Test failure on OSX arm64 is not related to my change. It is infra issue. Merging the code. |
Fixes #13573.
It optimizes
Integral type
Boolean logic with two operands when the first BB is conditional BB (e.g., BBJ_COND) and the second BB is conditional return (e.g., GT_RETURN > BBJ_RETURN).For example, it changes below logic:
In case the folding involves ANDing or comparison to GT_NE, it gets optimized only if the tree is evaluated as BOOLEAN.
Edit: Note: However, above 3 cases are not optimized because the operand of tree is not evaluated as boolean expression in the current JIT.
This PR does not optimze cases where it requries NOT transformation of x or y because the cost of NOT operation is large.
3 Basic Blocks are folded as below:
Before:
After:
Diff: