-
Notifications
You must be signed in to change notification settings - Fork 5.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
8283094: Add Ideal transformation: x + (con - y) -> (x - y) + con #7795
Conversation
…(con - y) into (x - y) + con.
👋 Welcome back CptGit! A progress list of the required criteria for merging this PR into |
@CptGit this pull request can not be integrated into git checkout addnode-PNewXPlus_ConMinusY_
git fetch https://git.openjdk.java.net/jdk master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push |
I think I have a better idea for this. During idealisation, we will transform every subtraction into an addition with the negation of the second operand, pushing the negation down the computation graph. This will simplify numerous rules we have with subtractions. Addition presents nice commutative and associative properties so the graph transformation during idealisation with be much easier. Before matching, we may have another strength reduction phase which will push the negations up the computation graph, transform the computations to be as compact as possible. This problem seems a lot like the problem we face in #7700 when eagerly strength reducing operations hurt our ability to perform other transformations by complicating the elements inside the graph. I believe this solution would simplify our arithmetic transformations and allow better numeric calculations. Similar to what has been discussed in #7395 , a more general solution would be much more valuable than trying to match every possible combinations. Thank you very much. |
I share the same opinion that John has from the linked #7395, to me it would be better if we would combine all these operations into a single method that can then decide on the specific optimization after analysis. This would also have the added bonus that related optimizations in the future could then leverage this framework and have an easier time implementing what they'd like to do. This may or may not require changes to C1 and the Interpreter to gather all the extra profiling information needed, I can't be the judge of that given my relative inexperience with C2. The only thing I'm unsure about is whether all the previous optimizations before this are all scattered across C2 or whether they all share variations of the same calculation, because we could take advantage of existing code if it's the latter. @merykitty would it be feasible to search for all of them in the C2 codebase? Should I create a JBS issue for this PR? |
@merykitty Thank you for your quick response. I agree a general solution is better and I also think addition is generally easier to optimize than subtraction. However considering this case, I noticed there are some existing transformation that does not follow this: for example jdk/src/hotspot/share/opto/addnode.cpp Line 307 in 5c408c1
Does the transformation hold all the time?
|
That is what I mean by saying that careless strength reduction restricts our ability to perform more efficient transformations. What I propose is we delay your mentioned transformation after idealisation has settled on the whole graph. |
Webrevs
|
Thank you. I was wondering if you mean other stage, for example |
One issue with such an approach is that it's then required to update all code that pattern match an expression with SubX node to now expect an (AddX (NegX ..) ..). PhaseIdealLoop::is_scaled_iv_plus_offset() for instance. And maybe there are not that many instances of code that require updating, but it's still needed to proceed carefully and double check, possibly update some code, write tests that verify the change does what's intended etc. So what appears relatively simple is going to be more work than expected and the risk associated with the change is higher than one might think. I doubt that's worth it. |
@rwestrel Thanks a lot for your information, it seems that the idea would turn out to be problematic with little applicable benefits then. |
test/hotspot/jtreg/compiler/c2/irTests/TestIRAddIdealXPlus_ConMinusY_.java
Outdated
Show resolved
Hide resolved
@@ -43,7 +43,9 @@ public static void main(String[] args) { | |||
"test8", "test9", "test10", | |||
"test11", "test12", "test13", | |||
"test14", "test15", "test16", | |||
"test17", "test18", "test19"}) | |||
"test17", "test18", "test19", | |||
"testXPlus_PosConMinusY_", "testXPlus_NegConMinusY_", |
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.
Please make the name uniform and put them in correct order, 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.
Renamed, does it look good to you now? 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.
Good.
@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 205 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, @TobiHartmann) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/reviewers 2 |
@CptGit |
Hello, can any reviewer review this if they get a chance? Thank you very much. |
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.
Looks good to me. I'll run some testing and report back once it finished.
All tests passed. |
/integrate |
@TobiHartmann Can you please sponsor the PR? thank you. |
/sponsor |
Going to push as commit c7755b8.
Your commit was automatically rebased without conflicts. |
Hello,
x + (con - y) -> (x - y) + con
is a widely seen pattern; however it is missing in current implementation, which prevents some obvious constant folding from happening, such asx + (1 - y) + 2
will be not optimized at all, rather than intox - y + 3
.This pull request adds this transformation.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/7795/head:pull/7795
$ git checkout pull/7795
Update a local copy of the PR:
$ git checkout pull/7795
$ git pull https://git.openjdk.java.net/jdk pull/7795/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 7795
View PR using the GUI difftool:
$ git pr show -t 7795
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/7795.diff