Skip to content
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

8347481: C2: Remove the control input of some nodes #23055

Closed
wants to merge 1 commit into from

Conversation

merykitty
Copy link
Member

@merykitty merykitty commented Jan 12, 2025

Hi,

While working on JDK-8347365, I noticed that there are some nodes that have their control inputs being set in a seemingly erroneous manner. This patch removes the control inputs for those nodes.

Please review this PR, thanks a lot.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8347481: C2: Remove the control input of some nodes (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23055/head:pull/23055
$ git checkout pull/23055

Update a local copy of the PR:
$ git checkout pull/23055
$ git pull https://git.openjdk.org/jdk.git pull/23055/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23055

View PR using the GUI difftool:
$ git pr show -t 23055

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23055.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 12, 2025

👋 Welcome back qamai! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jan 12, 2025

@merykitty 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:

8347481: C2: Remove the control input of some nodes

Reviewed-by: dfenacci, vlivanov, kvn

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 151 new commits pushed to the master branch:

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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 12, 2025
@openjdk
Copy link

openjdk bot commented Jan 12, 2025

@merykitty The following labels will be automatically applied to this pull request:

  • graal
  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added graal graal-dev@openjdk.org hotspot-compiler hotspot-compiler-dev@openjdk.org labels Jan 12, 2025
@mlbridge
Copy link

mlbridge bot commented Jan 12, 2025

Webrevs

@merykitty
Copy link
Member Author

/label remove graal

@openjdk openjdk bot removed the graal graal-dev@openjdk.org label Jan 12, 2025
@openjdk
Copy link

openjdk bot commented Jan 12, 2025

@merykitty
The graal label was successfully removed.

@dafedafe
Copy link
Contributor

Nice cleanup @merykitty. Thanks!
I was just wondering if there could be more nodes where the control input is wrongly set (possibly enough for a followup issue?)

@merykitty
Copy link
Member Author

@dafedafe Thanks, there's LoadKlassNode which very rarely takes a control input but the reason given does not convince me. However, it seems to be a less clear cut compared to these nodes so I think a separate RFE is more suitable.

Copy link
Contributor

@dafedafe dafedafe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I happened to notice that some other nodes seemed to give the possibility of setting the control input although it might not make sense (e.g. some Div*Node and Mod*Node) and I thought it might be worth having a global look at this at some point.

This fix seems totally OK for me as it is now. Thanks again @merykitty.

CMovePNode( Node *c, Node *bol, Node *left, Node *right, const TypePtr* t ) : CMoveNode(bol,left,right,t) { init_req(Control,c); }
CMovePNode(Node* bol, Node* left, Node* right, const TypePtr* t) : CMoveNode(bol, left, right, t) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked on history and this control setting was added at the very beginning.
May be it was done to avoid bypassing safepoints where oops could be modified (objects moved) and result of CMoveP before and after safepoint will be different.
I would be careful about changing it and CMoveN.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have thought about it and can't think of a reason for the control input.
Firstly, the oop map is created after scheduling and should take care of this seemlessly.
Secondly, the control input does not prevent a CMoveP from moving down past a safepoint. And since these nodes have depends_only_on_test == true, they can be moved from a test to an equivalent dominating test, skipping any safepoint in between, which means these nodes can be moved up past a safepoint, too.
As a result, I don't think the control input of CMoveP and CMoveN is necessary and can be safely removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any undesireable performance effects if CMove node floats up beyond its (original) control? It may have changed on modern hardware, but my recollection is cmov instructions were quite expensive to execute.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iwanowww A cmov is as cheap as an add so I don't think there will be any performance effect. I believe what you mean by cmov being expensive is that it has 1 cycle of latency on both of its inputs, while a well-predicted if diamond has 0 cycle of latency on the chosen input only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, my memory failed me. Indeed I was referring to relative slowness of cmov instructions compared to well-predicted conditional jumps which is not relevant here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a result, I don't think the control input of CMoveP and CMoveN is necessary and can be safely removed.

Okay. Let test it in JDK 25 and see how it goes. We have time to fix it if we find something wrong.
@dafedafe ran tier1-5 our testing and I don't see any new failures.

Copy link
Contributor

@iwanowww iwanowww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 16, 2025
@merykitty
Copy link
Member Author

Thanks a lot for your reviews and testing, let me integrate the patch.
/integrate

@openjdk
Copy link

openjdk bot commented Jan 17, 2025

Going to push as commit aa21de5.
Since your change was applied there have been 155 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jan 17, 2025
@openjdk openjdk bot closed this Jan 17, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jan 17, 2025
@openjdk
Copy link

openjdk bot commented Jan 17, 2025

@merykitty Pushed as commit aa21de5.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants