Skip to content

8380753: C2: RegMask::find_first_set() incorrectly returns partially contained sets for scalable vector registers#30890

Closed
shqking wants to merge 1 commit into
openjdk:masterfrom
shqking:8380753-regmask
Closed

8380753: C2: RegMask::find_first_set() incorrectly returns partially contained sets for scalable vector registers#30890
shqking wants to merge 1 commit into
openjdk:masterfrom
shqking:8380753-regmask

Conversation

@shqking

@shqking shqking commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Issue: compiler/loopopts/superword/TestAlignVectorFuzzer.java fails intermittently only on Neoverse-V1 machine (256-bit SVE) after JDK-8325467 with:

  Internal Error (/tmp/jdk-src/src/hotspot/share/opto/chaitin.cpp:1451), pid=101028, tid=101050
  assert(mask.can_represent(assigned)) failed: sanity

Root cause: On Neoverse-V1, the physical size of a scalable vector register exceeds RegMask::SlotsPerVecA (i.e. 2x larger). When querying a stack slot, RegMask::find_first_set() returns a register that is partially covered by the mask, violating can_represent().

Note-1: The failure is intermittent. I didn't check the jtreg code in details. I suppose the randomized and stress tests hit this corner case.

Note-2: JDK-8325467 converted a previously handled can_represent() check into an assertion. I suppose the bug is independent of other parts of JDK-8325467.

In this patch, we further validate the query result in RegMask::find_first_set().

Test-1: Run TestAlignVectorFuzzer.java case 100 times on Neoverse-V1 and all passes.

Test-2: Run tier1, tier2 and tier3 on Linux AArch64 and x86_64. No new failure.

Test-3: Add one unit test in gtest:RegMask. It fails on AArch64 if the change to regmask.cpp (that is done in this patch) is removed.

Co-contributed-by: Daniel Lunden daniel.lunden@oracle.com



Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8380753: C2: RegMask::find_first_set() incorrectly returns partially contained sets for scalable vector registers (Bug - P4)

Reviewers

Contributors

  • Daniel Lundén <dlunden@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30890

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

Using diff file

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

Using Webrev

Link to Webrev Comment

…contained sets for scalable vector registers

Issue: compiler/loopopts/superword/TestAlignVectorFuzzer.java fails
intermittently only on Neoverse-V1 machine (256-bit SVE) after
JDK-8325467 with:

```
  Internal Error (/tmp/jdk-src/src/hotspot/share/opto/chaitin.cpp:1451), pid=101028, tid=101050
  assert(mask.can_represent(assigned)) failed: sanity
```

Root cause: On Neoverse-V1, the physical size of a scalable vector
register exceeds RegMask::SlotsPerVecA (i.e. 2x larger). When querying a
stack slot, RegMask::find_first_set() returns a register that is
partially covered by the mask, violating can_represent().

Note-1: The failure is intermittent. I didn't check the jtreg code in
details. I suppose the randomized and stress tests hit this corner case.

Note-2: JDK-8325467 converted a previously handled can_represent() check
into an assertion. I suppose the bug is independent of other parts of
JDK-8325467.

In this patch, we further validate the query result in
RegMask::find_first_set().

Test-1: Run TestAlignVectorFuzzer.java case 100 times on Neoverse-V1 and
all passes.

Test-2: Run tier1, tier2 and tier3 on Linux AArch64 and x86_64. No new
failure.

Test-3: Add one unit test in gtest:RegMask. It fails on AArch64 if the
change to regmask.cpp (that is done in this patch) is removed.

Co-contributed-by: Daniel Lunden <daniel.lunden@oracle.com>
@bridgekeeper

bridgekeeper Bot commented Apr 23, 2026

Copy link
Copy Markdown

👋 Welcome back haosun! 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

openjdk Bot commented Apr 23, 2026

Copy link
Copy Markdown

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

8380753: C2: RegMask::find_first_set() incorrectly returns partially contained sets for scalable vector registers

Co-authored-by: Daniel Lundén <dlunden@openjdk.org>
Reviewed-by: aseoane, kvn, fyang

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 117 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 openjdk Bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Apr 23, 2026
@openjdk

openjdk Bot commented Apr 23, 2026

Copy link
Copy Markdown

@shqking 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 commented Apr 23, 2026

Copy link
Copy Markdown

The total number of required reviews for this PR has been set to 2 based on the presence of this label: hotspot-compiler. This can be overridden with the /reviewers command.

@openjdk openjdk Bot added the rfr Pull request is ready for review label Apr 23, 2026
@mlbridge

mlbridge Bot commented Apr 23, 2026

Copy link
Copy Markdown

Webrevs

@shqking

shqking commented Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

/contributor add @dlunde

@openjdk

openjdk Bot commented Apr 23, 2026

Copy link
Copy Markdown

@shqking
Contributor Daniel Lundén <dlunden@openjdk.org> successfully added.

@shqking

shqking commented Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

More tests we have done:

  • @dlunde helped test tier1 to tier4 (and additional Oracle-internal testing) on Windows x64, Linux x64, Linux aarch64, macOS x64, and macOS aarch64

I suppose this issue may affect RISC-V as well. I don't have the access to RISC-V. I was wondering if @RealFYang could help run some unit test? Thanks

  • test-1: Build with this patch and run make test TEST="gtest::RegMask". The expected result is pass.
  • test-2: Revert the change to regmask.cpp. Build and run make test TEST="gtest::RegMask". We expect this test would fail with the following assertion.
[ RUN      ] RegMask.find_first_set_scalable_vector_vm
/tmp/jdk-src/test/hotspot/gtest/opto/test_regmask.cpp:278: Failure
Expected equality of these values:
  rm.find_first_set(lrg, scalable_reg_slots)
    Which is: 387             <-- this value might be different on RISC-V
  OptoReg::Bad
    Which is: -1

@RealFYang

Copy link
Copy Markdown
Member

@shqking : Sure. Let me try it on linux-riscv64 with big vectors. Thanks for the ping.

@shqking

shqking commented Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

@shqking : Sure. Let me try it on linux-riscv64 with big vectors. Thanks for the ping.

Kindly remind that

  • we can run this unit test gtest::RegMask on any linux-riscv64. No need to select big vectors.
  • if we want to reproduce the intermittent jtreg failure compiler/loopopts/superword/TestAlignVectorFuzzer.java that we encountered on AArch64 Neoverse-V1 previously, linx-rsicv64 with big vectors is needed.

@anton-seoane

Copy link
Copy Markdown
Contributor

Thanks for this @shqking! The changeset looks good, to be on the safe side let me (re-)run a bit of testing

@anton-seoane anton-seoane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Testing passed, code looks good. Thanks!

@vnkozlov vnkozlov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@openjdk openjdk Bot added the ready Pull request is ready to be integrated label Apr 27, 2026

@RealFYang RealFYang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. My local test on linux-riscv64 w/wo big vectors is good.

@shqking

shqking commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for your reviews and tests.

/integrate

@openjdk

openjdk Bot commented Apr 28, 2026

Copy link
Copy Markdown

Going to push as commit b3f658d.
Since your change was applied there have been 125 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 Apr 28, 2026
@openjdk openjdk Bot closed this Apr 28, 2026
@openjdk openjdk Bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 28, 2026
@openjdk

openjdk Bot commented Apr 28, 2026

Copy link
Copy Markdown

@shqking Pushed as commit b3f658d.

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

@shqking shqking deleted the 8380753-regmask branch April 28, 2026 10:35
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