Skip to content

8371603: C2: Missing Ideal optimizations for load and store vectors on SVE#28651

Closed
XiaohongGong wants to merge 3 commits intoopenjdk:masterfrom
XiaohongGong:JDK-8371603
Closed

8371603: C2: Missing Ideal optimizations for load and store vectors on SVE#28651
XiaohongGong wants to merge 3 commits intoopenjdk:masterfrom
XiaohongGong:JDK-8371603

Conversation

@XiaohongGong
Copy link

@XiaohongGong XiaohongGong commented Dec 4, 2025

Problem:

This issue occurs on a 256-bit SVE machine, caused by the following problematic pattern in LoadVectorNode::Ideal():

Node* LoadVectorNode::Ideal(PhaseGVN* phase, bool can_reshape) {
  const TypeVect* vt = vect_type();
  if (Matcher::vector_needs_partial_operations(this, vt)) {
    return VectorNode::try_to_gen_masked_vector(phase, this, vt);
  }
  return LoadNode::Ideal(phase, can_reshape);
}

The condition Matcher::vector_needs_partial_operations(this, vt) returns true for LoadVectorNode with 256-bit vector size even when the vector size equals the maximum vector size on SVE. In such cases, when VectorNode::try_to_gen_masked_vector() returns nullptr, the method exits early without calling LoadNode::Ideal(). This results in missing crucial optimizations that would normally be applied by the superclass.

This code was introduced by https://bugs.openjdk.org/browse/JDK-8286941 to generate vector masks for partial vector operations, but it failed to ensure that the superclass Ideal() method is always invoked when no transformation is applied.

Solution:

This patch addresses the issue through two changes:

  1. Refine Matcher::vector_needs_partial_operations() to return true only when the vector node genuinely represents a partial vector operation that requires masking.
  2. Modify VectorNode::try_to_gen_masked_vector() to never return nullptr, ensuring the superclass Ideal() method is always invoked when no transformation is applied.

Testing:

  • Verified on different SVE platforms with different vector sizes (128|256|512 bits).
  • Verified on X86 platforms with different avx options (-XX:UseAVX=1|2|3).
  • Added two new IR tests to verify 1) previously missing optimizations for LoadVector/StoreVector are now applied, and 2) that mask and the correct IR patterns are generated for partial vector operations.

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-8371603: C2: Missing Ideal optimizations for load and store vectors on SVE (Bug - P3)(⚠️ The fixVersion in this issue is [26] but the fixVersion in .jcheck/conf is 27, a new backport will be created when this pr is integrated.)

Reviewers

Contributors

  • Emanuel Peter <epeter@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28651

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 4, 2025

👋 Welcome back xgong! 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 Dec 4, 2025

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

8371603: C2: Missing Ideal optimizations for load and store vectors on SVE

Co-authored-by: Emanuel Peter <epeter@openjdk.org>
Reviewed-by: epeter, erfang, haosun

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

@XiaohongGong
Copy link
Author

/contributor add @eme64

@openjdk
Copy link

openjdk bot commented Dec 4, 2025

@XiaohongGong
Contributor Emanuel Peter <epeter@openjdk.org> successfully added.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Dec 4, 2025
@openjdk
Copy link

openjdk bot commented Dec 4, 2025

@XiaohongGong 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.

@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 4, 2025
@XiaohongGong
Copy link
Author

Hi @eme64 , this is the fixing for the crash issue reported on aws machine. Could you please help take a look? Thanks a lot!

@mlbridge
Copy link

mlbridge bot commented Dec 4, 2025

Webrevs

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.

@XiaohongGong Thanks for taking this over from me and fixing this so quickly, much appreciated!

Thanks for adding my regression tests and for the attribution :)

I only have a minor comment below. Otherwise, the code looks good to me. But since I'm not an SVE specialist, it would be good if someone with deeper knowledge would do a deeper review of the specific SVE parts.

Once an SVE specialist gives the approval for the PR, I'l run some internal testing and approve from my side :)

Ah, and one more thing: you should change the PR title to be more descriptive of the issue. The assert that was hit is only a far removed symptom. I would suggest:

C2 SVE: missing Ideal optimizations for load and store vectors

@XiaohongGong
Copy link
Author

Ah, and one more thing: you should change the PR title to be more descriptive of the issue. The assert that was hit is only a far removed symptom. I would suggest:

C2 SVE: missing Ideal optimizations for load and store vectors

The new title looks good to me. Thanks!

@XiaohongGong XiaohongGong changed the title 8371603: C2: assert(_inputs.at(alias_idx) == nullptr || _inputs.at(alias_idx) == load->in(1)) failed 8371603: C2: Missing Ideal optimizations for load and store vectors on SVE Dec 5, 2025
@XiaohongGong
Copy link
Author

Hi @eme64, I'v updated the patch based on your suggestion. Would you mind taking another look? Thanks!

@XiaohongGong
Copy link
Author

Hi @theRealAph , would you mind taking a look at this patch especially the AArch64 part? Thanks a lot!

@XiaohongGong
Copy link
Author

Hi @erifan @shqking , could you please help take a look at this PR? Thanks a lot!

Copy link
Contributor

@erifan erifan left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix.

Copy link
Contributor

@shqking shqking left a comment

Choose a reason for hiding this comment

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

Thanks for your work. LGTM.

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.

Nice, thanks for the updates. I think this looks cleaner now.

I have one more nit below. But I'll run some sanity testing from my side already.

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.

Tests pass. Thanks for the updates.

And thanks for fixing it so swiftly and for the attribution 😊

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 9, 2025
@XiaohongGong
Copy link
Author

Thanks so much for your review @eme64 , @shqking and @erifan !

@XiaohongGong
Copy link
Author

/integrate

@openjdk
Copy link

openjdk bot commented Dec 10, 2025

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

openjdk bot commented Dec 10, 2025

@XiaohongGong Pushed as commit b6732d6.

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

@XiaohongGong XiaohongGong deleted the JDK-8371603 branch December 10, 2025 02:21
@XiaohongGong
Copy link
Author

/backport jdk26

@openjdk
Copy link

openjdk bot commented Dec 10, 2025

@XiaohongGong The target repository jdk26 is not a valid target for backports.
List of valid target repositories: openjdk/jdk, openjdk/jdk11u, openjdk/jdk11u-dev, openjdk/jdk17u, openjdk/jdk17u-dev, openjdk/jdk21u, openjdk/jdk21u-dev, openjdk/jdk25u, openjdk/jdk25u-dev, openjdk/jdk8u, openjdk/jdk8u-dev, openjdk/jfx, openjdk/jfx17u, openjdk/jfx21u, openjdk/jfx25u, openjdk/lilliput-jdk17u, openjdk/lilliput-jdk21u, openjdk/lilliput-jdk25u, openjdk/shenandoah-jdk21u, openjdk/shenandoah-jdk8u.
Supplying the organization/group prefix is optional.

There is a branch jdk26 in the current repository openjdk/jdk.
To target a backport to this branch in the current repository use:
/backport :jdk26

@XiaohongGong
Copy link
Author

/backport :jdk26

@openjdk
Copy link

openjdk bot commented Dec 10, 2025

@XiaohongGong the backport was successfully created on the branch backport-XiaohongGong-b6732d60-jdk26 in my personal fork of openjdk/jdk. To create a pull request with this backport targeting openjdk/jdk:jdk26, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit b6732d60 from the openjdk/jdk repository.

The commit being backported was authored by Xiaohong Gong on 10 Dec 2025 and was reviewed by Emanuel Peter, Eric Fang and Hao Sun.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk:

$ git fetch https://github.com/openjdk-bots/jdk.git backport-XiaohongGong-b6732d60-jdk26:backport-XiaohongGong-b6732d60-jdk26
$ git checkout backport-XiaohongGong-b6732d60-jdk26
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk.git backport-XiaohongGong-b6732d60-jdk26

⚠️ @XiaohongGong You are not yet a collaborator in my fork openjdk-bots/jdk. An invite will be sent out and you need to accept it before you can proceed.

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