Skip to content

Conversation

@marc-chevalier
Copy link
Member

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

In bool LibraryCallKit::inline_vectorizedMismatch() the region created at:

Node* exit_block = new RegionNode(PATH_LIMIT);

may have only one input, and be a copy (that is no self-loop) and a single input. It is thus safe to remove. Yet, in the reproducer case, the node is short-circuited, but stays in the graph after IGVN.

Left, after Parsing/before IGVN; right, after IGVN:

On the left, the ⚠️ is there because the Region doesn't have a self loop, which is expected for copies. On the right, it still doesn't have a self-loop, but IGV is also complaining the Region has no successor.

This transformation comes from IfNode::Ideal, that calls IfNode::Ideal_common, that calls Node::remove_dead_region, that shortcuts a trivial Region input:

if( n->is_Region() && n->as_Region()->is_copy() ) {
Node *m = n->nonnull_req();
set_req(0, m);
return true;
}

Yet, the Region node is never enqueued for IGVN, so stays in the graph. This is not nice because it gives both:

  • a control node (50 Proj) has 2 successors,
  • a control node (46 Region) has 0 successors.

While at the end of IGVN, we could expect the graph to be cleaned up. There are couple ways of doing, each being enough by itself:

  1. explicitly record for IGVN the region node in LibraryCallKit::inline_vectorizedMismatch, and not hoping it would be collected by another consequence
  2. change Node::remove_dead_region to use set_req_X instead of set_req, so that if the Region goes dead, it will be removed.
  3. not introduce the region node in LibraryCallKit::inline_vectorizedMismatch if we are going to have only one path, and thus avoid the problem entirely.

The solution 3. is really not easy and would require quite some code restructuring for simply saving removing a node. After discussing with @chhagedorn, we concluded that the solution 1. was probably the best:

  • usually, functions similar to inline_vectorizedMismatch call record_for_igvn themselves,
  • unlike what I assumed at first seeing remove_dead_region, it's not a general problem at all: I couldn't find another case without using inline_vectorizedMismatch where the Region is put aside, and not entirely disconnected quickly after, but the Region is always processed in the same IGVN when remove_dead_region makes it dead.

And then, we find that:

This was found because it makes a check of JDK-8350864 to fail. My plan is to add this structural invariant check to the test once the flag is integrated, as for now, the test need manual inspection to see a difference. It's also not really possible to write an IR test with it: the Region node is not reachable by under (use to def traversal from Root), so the printout of the graph doesn't show the Region node, even if the 50 Proj above is indeed printed to have 2 outputs, only the 57 If is actually printed.


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-8359121: C2: Region added by vectorizedMismatch intrinsic can survive as a dead node after IGVN (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25749

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25749.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

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

8359121: C2: Region added by vectorizedMismatch intrinsic can survive as a dead node after IGVN

Reviewed-by: thartmann, chagedorn

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 6 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
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.

@openjdk openjdk bot added graal graal-dev@openjdk.org hotspot-compiler hotspot-compiler-dev@openjdk.org labels Jun 11, 2025
@marc-chevalier marc-chevalier marked this pull request as ready for review June 11, 2025 12:58
@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

Copy link
Member

@TobiHartmann TobiHartmann left a comment

Choose a reason for hiding this comment

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

Nice analysis Marc. I also prefer solution (1) and the fix looks good to me.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 11, 2025
Copy link
Member

@chhagedorn chhagedorn left a comment

Choose a reason for hiding this comment

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

Nice analysis and summary! As you've already mentioned in the description, we found solution 1 to be the best fit.

@marc-chevalier
Copy link
Member Author

/integrate

Thanks both for review!

@openjdk
Copy link

openjdk bot commented Jun 12, 2025

Going to push as commit b6ec93b.
Since your change was applied there have been 19 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 Jun 12, 2025
@openjdk openjdk bot closed this Jun 12, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 12, 2025
@openjdk
Copy link

openjdk bot commented Jun 12, 2025

@marc-chevalier Pushed as commit b6ec93b.

💡 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

graal graal-dev@openjdk.org hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants