-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
base: master
Are you sure you want to change the base?
8347901: C2 should remove unused leaf / pure runtime calls #25760
Conversation
👋 Welcome back mchevalier! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
@marc-chevalier The following labels will be automatically applied to this pull request:
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. |
Webrevs
|
Just a side comment: "Integer division is not pure as dividing by zero is throwing." is only true for some platforms. See JDK-8299857. |
Right. Yet, it's safe to consider it as non-pure, as an over-approximation, but it could be refined. |
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.
@marc-chevalier Nice work!
I have a first set of qestions / suggestions :)
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); | ||
} |
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.
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?
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.
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?
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 withProjNode
: the n-th projection of aTupleNode
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
Issue
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