Skip to content

8347901: C2 should remove unused leaf / pure runtime calls #25760

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

marc-chevalier
Copy link
Member

@marc-chevalier marc-chevalier commented Jun 11, 2025

A first part toward a better support of pure functions, but this time, with guidance from @iwanowww.

Pure Functions

Pure functions (considered here) are functions that have no side effects, no effect on the control flow (no exception or such), cannot deopt etc.. It's really a function that you can execute anywhere, with whichever arguments without effect other than wasting time. Integer division is not pure as dividing by zero is throwing. But many floating point functions will just return NaN or +/-infinity in problematic cases.

Scope

We are not going all powerful for now! It's mostly about identifying some pure functions and being able to remove them if the result is unused. Some other things are not part of this PR, on purpose. Especially, this PR doesn't propose a way to move pure calls around. The reason is that pure calls are later expanded into regular calls, which require a control input. To be able to do the expansion, we just keep the control in the pure call as well.

Implementation Overview

We created here some new node kind for pure calls, inheriting leaf calls, that are expanded into regular leaf calls during final graph reshaping. The possibility to support pure call directly in AD file is left open.

This PR also introduces TupleNode (largely based on an original idea/implem of @iwanowww), that just tie multiple input together and play well with ProjNode: the n-th projection of a TupleNode is the n-th input of the tuple. This is a convenient way to skip and remove nodes from the graph while delegating the difficulty of the surgery to the trusted IGVN's implementation.

Thanks,
Marc


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-8347901: C2 should remove unused leaf / pure runtime calls (Enhancement - P3)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25760

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 11, 2025

👋 Welcome back mchevalier! 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 Jun 11, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Jun 11, 2025

@marc-chevalier 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.

@marc-chevalier marc-chevalier marked this pull request as ready for review June 11, 2025 16:23
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 11, 2025
@mlbridge
Copy link

mlbridge bot commented Jun 11, 2025

Webrevs

@TheRealMDoerr
Copy link
Contributor

Just a side comment: "Integer division is not pure as dividing by zero is throwing." is only true for some platforms. See JDK-8299857.

@marc-chevalier
Copy link
Member Author

Right. Yet, it's safe to consider it as non-pure, as an over-approximation, but it could be refined.

Copy link
Contributor

@eme64 eme64 left a comment

Choose a reason for hiding this comment

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

@marc-chevalier Nice work!

I have a first set of qestions / suggestions :)

Comment on lines +123 to +126
if (ctrl->Opcode() == Op_Tuple) {
// Jumping over Tuples: the i-th projection of a Tuple is the i-th input of the Tuple.
ctrl = ctrl->in(_con);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to special-case this here? Why does the ProjNode::Identity not suffice? Are there potentially other locations where we now would need this special logic?

Copy link
Member Author

Choose a reason for hiding this comment

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

That is a good question. That is something I picked from Vladimir's implementation and it seemed legitimate. But now you say it, is it needed? Not sure. I'm trying to find that out. Would ::Identity be enough? It's tempting to say so, right! I'd say it can be not enough if we need adr_type before idealizing the ProjNode (no idea if that happens). Is there any other places to adapt? One could think so, but actually, I can't find such an example. Other methods of ProjNode for instance rely on the type of the input (which is correctly handled in TupleNode), and so should already work fine.

I'm trying to understand what happens if we don't have that. But maybe @iwanowww would have some helpful insight?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants