Skip to content

Conversation

@benoitmaillard
Copy link
Contributor

@benoitmaillard benoitmaillard commented Nov 21, 2025

This PR addresses a missed optimization in PhaseIterGVN for MemBarAcquire nodes caused by a missing notification during parsing.

The missed optimization in question is the removal of the the in(MemBarNode::Precedent) edge for
MemBarAcquire nodes when the the MemBar is the only user of its input. This was intially
introduced to get rid of unused Load nodes that were only kept alive by such an edge.

Node *MemBarNode::Ideal(PhaseGVN *phase, bool can_reshape) {
if (remove_dead_region(phase, can_reshape)) return this;
// Don't bother trying to transform a dead node
if (in(0) && in(0)->is_top()) {
return nullptr;
}

In our case, it happens that the Load node gets folded to a constant during the initial
_gvn.transform call in GraphKit::make_load. Because the value is converted before being
returned, we end up with two constant nodes: one ConL and one ConI. The ConL only
has one usage, and this triggers the optimization during verification.

static int test0() {
    var c = new MyClass();
    // the conversion ensures that the ConL node only has one use
    // in the end, which triggers the optimization
    return (int) c.l;
}

The optimization is not triggered earlier during when we apply _gvn.transform on the membar,
because it requires can_reshape, which is set to false in when we call apply_ideal in
PhaseGVN::transform.

For this reason, we should call record_for_igvn(membar) after the MemBar is created
and transformed in GraphKit::insert_mem_bar to make sure it gets an Ideal pass with
can_reshape later.

This issue was initially filed for Valhalla, because a condition in GraphKit::make_load
prevents its from occurring when boxing elimination is enabled. Boxing elimination is
disabled temporarily in Valhalla (see JDK-8328675),
which caused the issue to appear, but by using -XX:-EliminateAutoBox it became clear
that the issue was on mainline.

Testing

Thank you for reviewing!


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-8367627: C2: Missed Ideal() optimization opportunity with MemBar (Bug - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28448

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 21, 2025

👋 Welcome back bmaillard! 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 Nov 21, 2025

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

@openjdk openjdk bot changed the title 8367627 8367627: C2: Missed Ideal() optimization opportunity with MemBar Nov 21, 2025
@openjdk
Copy link

openjdk bot commented Nov 21, 2025

@benoitmaillard The following label will be automatically applied to this pull request:

  • hotspot-compiler

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

@benoitmaillard benoitmaillard changed the title 8367627: C2: Missed Ideal() optimization opportunity with MemBar 8367627 Nov 21, 2025
@openjdk openjdk bot changed the title 8367627 8367627: C2: Missed Ideal() optimization opportunity with MemBar Nov 21, 2025
@benoitmaillard benoitmaillard marked this pull request as ready for review November 21, 2025 18:27
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 21, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 21, 2025

Webrevs

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

Labels

hotspot-compiler [email protected] rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

1 participant