Skip to content

Conversation

@marc-chevalier
Copy link
Member

@marc-chevalier marc-chevalier commented Jan 20, 2026

The test TestScalarConditionalMoveCmpObj.java tests whether code such as

r[i] = (a[i] != b[i]) ? cc : dd;

where a and b are Object[] gives a CMoveNode. Without Valhalla, we get a simple If -> If(True|False) -> Region diamond

diamond

that is simplified as a CMove.

cmove

Only this simple shape is simplified:

// Attempt to replace a Phi with a conditional move. We have some pretty
// strict profitability requirements. All Phis at the merge point must
// be converted, so we can remove the control flow. We need to limit the
// number of c-moves to a small handful. All code that was in the side-arms
// of the CFG diamond is now speculatively executed. This code has to be
// "cheap enough". We are pretty much limited to CFG diamonds that merge
// 1 or 2 items with a total of 1 or 2 ops executed speculatively.
Node *PhaseIdealLoop::conditional_move( Node *region ) {

But with Valhalla, since operands could be value objects, the logic is a lot more complex: are pointer equal? If not, are one of both operands null? If both aren't null, are the operand the same class? If so... All being eventually concluded with a call to isSubstitutable. This can't be simplified as a CMove (or not easily).

Even warm up isn't enough: while a[i] and b[i] are guessed to be exactly Object, this still requires a more complex logic than a diamond. Schematically: are pointers equal? If not, is lhs null (that is enough to conclude they are different objects)? If so, trap; if not, is lhs of the speculated (non-value) type? If so, they are different; if not, trap. That is too complicated to make a CMove.

A solution is to make sure we can prove, rather than speculate, that operands are not value objects. Instead of making a and b arrays of Object that can be value types at runtime, we make them arrays of a non-abstract non-value type. This cannot be derived into a value class, so it's fine. And the test pass again!

I've also done a bit of side fixup in these tests: fixing package name and call init on the arrays used for the int flavor of the test (method private static void TestScalarConditionalMoveCmpObj::init(int[] a) was suspiciously unused).

Thanks,
Marc


Progress

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

Issue

  • JDK-8374122: [lworld] compiler/c2/cmove/TestScalarConditionalMoveCmpObj.java fails with ir mismatches when preview enabled, post jdk-27+3 (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1934

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/1934.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 20, 2026

👋 Welcome back mchevalier! A progress list of the required criteria for merging this PR into lworld 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 Jan 20, 2026

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

8374122: [lworld] compiler/c2/cmove/TestScalarConditionalMoveCmpObj.java fails with ir mismatches when preview enabled, post jdk-27+3

Reviewed-by: qamai, thartmann

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 128 new commits pushed to the lworld 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 lworld branch, type /integrate in a new comment.

@marc-chevalier marc-chevalier marked this pull request as ready for review January 20, 2026 11:07
@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 20, 2026
@mlbridge
Copy link

mlbridge bot commented Jan 20, 2026

Webrevs

Copy link
Member

@merykitty merykitty left a comment

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 Jan 20, 2026
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.

Looks good to me too!

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

Labels

ready Pull request is ready to be integrated rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

3 participants