-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8281453: New optimization: convert ~x into -1-x when ~x is used in an arithmetic expression #7376
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
👋 Welcome back CptGit! A progress list of the required criteria for merging this PR into |
A bug has been filed https://bugs.openjdk.java.net/browse/JDK-8281453. |
Webrevs
|
Since |
@CptGit This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
Thank you for your comment. I am looking at this pending PR again. I drafted it for now until I get a rfr version. While I am implementing your suggestion, I found another typical optimization that is missing, which is pushing constant to right from |
Hello @merykitty I finished converting |
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.
This change touches the same code as #7795
I suggest to update after that one is pushed.
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.
Optimization you proposed does not match RFE description and title.
You do only: ~x
or (x ^ (-1))->
(-1 - x)`
As result this should be Xor nodes ideal transformation. I don't even think you need such transformation if rhs
and lhs
are not constants because I assume XOR
and SUB
hw instructions have the same latency.
I suggest you to redo performance testing after you merged #7795 changes.
Thanks for reviewing. @vnkozlov
The initial description is somewhat out of date because I adopted @merykitty 's suggestion to include all the cases enabled from
Will redo and post results. |
@CptGit This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@CptGit This pull request has been inactive for more than 16 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
@merykitty I moved things to |
@merykitty I removed the use check. Does it look good to you? I did not include test |
I think it looks good, thanks. |
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 will test latest version.
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.
Latest testing passed.
@CptGit Did you updated performance numbers for latest changes? Did they change? |
Good. It is ready for integration. |
/integrate |
@CptGit This pull request has not yet been marked as ready for integration. |
I think, it is because PR title does not match JBS entry title. |
~x
into -1-x
when ~x
is used in an arithmetic expression
@CptGit This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 91 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@vnkozlov) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/integrate |
/sponsor |
Going to push as commit 5dd851d.
Your commit was automatically rebased without conflicts. |
Similar to
(~x)+c
->(c-1)-x
and~(x+c)
->(-c-1)-x
in #6858, we can also introduce similar optimizations for subtraction,c-(~x)
->x+(c+1)
and~(c-x)
->x+(-c-1)
.To generalize, I convert
~x
into-1-x
when~x
is used only in arithmetic expression. For example,c-(~x)
will be converted intoc-(-1-x)
which will match other pattern and will be transformed again in next iteration and finally becomex+(c+1)
.Also the conversion from
~x
into-1-x
happens whenx
is an arithmetic expression itself. For example,~(x+c)
will be transformed into-1-(x+c)
and eventually(-c-1)-x
.The results of the microbenchmark are as follows:
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/7376/head:pull/7376
$ git checkout pull/7376
Update a local copy of the PR:
$ git checkout pull/7376
$ git pull https://git.openjdk.org/jdk pull/7376/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 7376
View PR using the GUI difftool:
$ git pr show -t 7376
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/7376.diff