Skip to content

Conversation

@Hamlin-Li
Copy link

@Hamlin-Li Hamlin-Li commented Nov 13, 2025

Hi,

This pr add CMoveF/D on riscv, which enable vectorization of statement like: op_1 bop op_2 ? res_f_d_1 : res_f_d_2 in a loop.

This pr is also a preparation for further vectorization in #28231.

Previously it's #25341, but at that time, C2 SLP has some issue with unsigned comparison, which is now fixed, so it's good to continue the work.

Test

Jtreg

in progress...

Performance

Column names meanings:

  • p: with patch
  • p+v: with patch, -XX:+UseVectorCmov -XX:+UseCMoveUnconditionally turned on
  • m: without patch
  • m+v: without patch, -XX:+UseVectorCmov -XX:+UseCMoveUnconditionally turned on

Average improvement

NOTE: With only this PR, it brings performance benefit in case of CMoveF+CmpF, CMoveD+ComD, CMoveF+CmpI, CMoveD+CmpL. The data below is based on fullly implmenting the vectorization of CMoveI/L/F/D+CmpI/L/F/D, which will be achieved by #28231.

For details, check the performance data in #25341 on riscv.

Opt (m/p) Opt (m+v/p+v) Opt (p/p+v) Opt (m/p+v)
1.022782609 2.198717391 2.162673913 2.199

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-8357551: RISC-V: support CMoveF/D vectorization (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28309

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@RealFYang
Copy link
Member

@Hamlin-Li : Thanks for the update. I am having another look.

Copy link
Member

@RealFYang RealFYang left a comment

Choose a reason for hiding this comment

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

Latest version seems fine to me. Thanks for the update.
As we are very close to JDK 26 rampdown (2025/12/04), I suggest we postpone this to JDK 27.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 3, 2025
@eme64
Copy link
Contributor

eme64 commented Dec 3, 2025

/reviewers 2

I can help review this as well, but currently there is a lot going on with JDK26 bugs. Hopefully things settle down in a few weeks.

@openjdk
Copy link

openjdk bot commented Dec 3, 2025

@eme64
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Dec 3, 2025
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 8, 2025
@Hamlin-Li
Copy link
Author

@luhenry Thank you!

@Hamlin-Li
Copy link
Author

/integrate

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 work! I did not review the RISC-V specific changes, but had a look at the tests. Wow, there are a lot of them, and that's a good thing :)

I have a few comments below, to consider for improvement.

Comment on lines +1562 to +1564
// @IR(counts = {IRNode.CMOVE_I, ">0", IRNode.CMP_L, ">0"},
// applyIf = {"UseVectorCmov", "false"},
// applyIfPlatform = {"riscv64", "true"})
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these all commented out?

Comment on lines +314 to +356
private static void init(int[] a) {
for (int i = 0; i < SIZE; i++) {
a[i] = RANDOM.nextInt();
}
}

private static void init(long[] a) {
for (int i = 0; i < SIZE; i++) {
a[i] = RANDOM.nextLong();
}
}

private static void init(float[] a) {
for (int i = 0; i < SIZE; i++) {
a[i] = switch(RANDOM.nextInt() % 20) {
case 0 -> Float.NaN;
case 1 -> 0;
case 2 -> 1;
case 3 -> Float.POSITIVE_INFINITY;
case 4 -> Float.NEGATIVE_INFINITY;
case 5 -> Float.MAX_VALUE;
case 6 -> Float.MIN_VALUE;
case 7, 8, 9 -> RANDOM.nextFloat();
default -> Float.intBitsToFloat(RANDOM.nextInt());
};
}
}

private static void init(double[] a) {
for (int i = 0; i < SIZE; i++) {
a[i] = switch(RANDOM.nextInt() % 20) {
case 0 -> Double.NaN;
case 1 -> 0;
case 2 -> 1;
case 3 -> Double.POSITIVE_INFINITY;
case 4 -> Double.NEGATIVE_INFINITY;
case 5 -> Double.MAX_VALUE;
case 6 -> Double.MIN_VALUE;
case 7, 8, 9 -> RANDOM.nextDouble();
default -> Double.longBitsToDouble(RANDOM.nextLong());
};
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You could use Generators.java, it creates "interesting" distributions, and makes sure we use sufficient special case values.

@openjdk
Copy link

openjdk bot commented Dec 8, 2025

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

openjdk bot commented Dec 8, 2025

@Hamlin-Li Pushed as commit 6700baa.

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

@eme64
Copy link
Contributor

eme64 commented Dec 8, 2025

@Hamlin-Li Oh bummer, I was just a few seconds too slow 😢

@Hamlin-Li
Copy link
Author

Nice work! I did not review the RISC-V specific changes, but had a look at the tests. Wow, there are a lot of them, and that's a good thing :)

I have a few comments below, to consider for improvement.

@eme64 Thanks for having a look.
Seems there is a race condition here. :) I just triggered the integration.
I'll file new bug to address your comment.

@eme64
Copy link
Contributor

eme64 commented Dec 8, 2025

@Hamlin-Li Sounds good. I don't blame you, you had 2 reviewers ;)
I also did not run internal testing. Most likely everything will be fine.
Thanks for addressing my comments in the future, much appreciated!

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

Labels

core-libs core-libs-dev@openjdk.org hotspot hotspot-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.

4 participants