-
Couldn't load subscription status.
- Fork 6.1k
8353551: C2: Constant folding for ReverseBytes nodes #24382
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 hgreule! A progress list of the required criteria for merging this PR into |
|
@SirYwell 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 682 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 (@iwanowww, @eme64) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
Webrevs
|
src/hotspot/share/opto/subnode.cpp
Outdated
| } | ||
|
|
||
| template<typename T, BasicType B> | ||
| const Type* reverse_bytes(const Node* node, PhaseGVN* phase) { |
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.
Could this be templated with TypeLong/TypeInt instead of BasicType? There is a try_cast that @merykitty added in #17508 that might help.
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 wouldn't change much, but yes. Generally this is an example where #17508 shines, as the code could be generalized to just reverse the bytes of the KnownBits structure. Whether this PR waits until then or we refactor the code afterwards isn't that important to me.
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 didn’t intend to advocate for waiting for that PR. try_cast is tiny and could be added independently. I have just been looking for things that could generally help with unifying TypeInt/TypeLong implementations.
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.
Personally, I'd prefer to see a unified generic version of ReverseBytesNode::Value() rather than multiple specializations (even templated ones).
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.
@j3graham I mainly want to avoid conflicts or duplicated solutions. I meant that after #17508 this code can be further generalized anyway, allowing to use the try_cast function then. This can obviously happen in a separate PR, if this one is integrated before.
@iwanowww I'm not sure if that's possible without more duplication. We need to choose the correct byteswap implementation depending on the node's type. Please let me know if I'm missing something.
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.
Okay, I see. That works for me. One problem though, there currently isn't a common ReverseBytesNode type, so I'd need to add that. And I assume that should be a TypeNode then? In that case, as ReverseBytes*Nodes are InvolutionNodes, would InvolutionNode need to be a TypeNode? Or can I use multiple inheritance? (I didn't see any example of that in current Node types). Both are doable, and the first might even make sense, but I'm not sure if it's a bit much for this PR.
Or do you want me to (temporarily) duplicate the Value code (i.e. move more code from the templated function to the Value functions, and only keep the simple reverse_bytes from your snippet)?
Alternatively, I'd also be fine to put this PR on hold and make InvolutionNode a TypeNode first, or whatever you think is best. Please let me know what you think.
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.
And I assume that should be a TypeNode then?
Why do you think it benefits from becoming a TypeNode?
In that case, as ReverseBytes*Nodes are InvolutionNodes, would InvolutionNode need to be a TypeNode? Or can I use multiple inheritance?
We try to avoid multiple inheritance in JVM and C2 doesn't use any AFAIK.
Actually, I had an afterthought about InvolutionNode after approving it. It looks a bit weird to model "involution" property through inheritance. (Primarily, because it's hard to mix multiple properties.) Node flags would be a better fit IMO.
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.
For now, I suggest to just add a superclassReverseBytesNode which extends InvolutionNode and place Value there.
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 do you think it benefits from becoming a
TypeNode?
Oh yeah I somehow confused myself there successfully.
Actually, I had an afterthought about
InvolutionNodeafter approving it. It looks a bit weird to model "involution" property through inheritance. (Primarily, because it's hard to mix multiple properties.) Node flags would be a better fit IMO.
That would work, although it would make the common implementation more difficult I think. Also AddNode similarly models the "addition in a (semi)-ring" property, but there's clearly more shared code there (and the property can't be modeled as a flag there because the respective multiplicative operation is defined there too).
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.
@iwanowww I applied your suggestion now. Please let me know if this is good now.
src/hotspot/share/opto/subnode.cpp
Outdated
| } | ||
|
|
||
| template<typename T, BasicType B> | ||
| const Type* reverse_bytes(const Node* node, PhaseGVN* phase) { |
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.
Personally, I'd prefer to see a unified generic version of ReverseBytesNode::Value() rather than multiple specializations (even templated ones).
|
|
||
| @DontCompile | ||
| public void assertResultI() { | ||
| Asserts.assertEQ(Integer.reverseBytes(0x04030201), testI1()); |
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, add more test cases (specifically, with negative constants).
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 added cases with a leading 0x80 byte now
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.
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.
Overall, looks good. Submitted it for testing.
src/hotspot/share/opto/subnode.cpp
Outdated
| return TypeH::make((float)sqrt((double)f)); | ||
| } | ||
|
|
||
| const Type* reverse_bytes(int opcode, const Type* con) { |
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, declare it as static.
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.
Testing results are good.
|
@iwanowww thanks, I addressed your last comment. |
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.
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.
Nice, the code looks even better now :)
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
| package compiler.c2.irTests; |
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.
Can you please move the test to a more specific directory?
The irTests directory was a bit of a mistake. I think this would make more sense in test/hotspot/jtreg/compiler/c2/gvn/.
|
@iwanowww I see you did some internal testing, but not for what version. Should we re-run testing? |
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 looks good to me.
But before you integrate:
I also launched testing again, just in case. Please ping me again in 24h for the results :)
|
Thanks for testing again @eme64. Are the results in? |
|
@SirYwell They are almost completed, but so far no failure :) |
|
@eme64 just to make sure, I assume we can integrate this now? |
|
@SirYwell Yes, it is all green 🟢 Ship it :) 🚢 |
|
Thanks for your reviews! /integrate |
|
@SirYwell Thanks for the work :) |
|
Going to push as commit de801fe.
Your commit was automatically rebased without conflicts. |
This change implements constant folding for ReverseBytes nodes.
Currently,
byteswapis included transitively byreverse_bits.hpp. I'm not sure if this is fine or if I need to add an explicit include there.I appreciate any reviews and comments.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24382/head:pull/24382$ git checkout pull/24382Update a local copy of the PR:
$ git checkout pull/24382$ git pull https://git.openjdk.org/jdk.git pull/24382/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 24382View PR using the GUI difftool:
$ git pr show -t 24382Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24382.diff
Using Webrev
Link to Webrev Comment