RFR: 8357554: Enable vectorization of Bool -> CMove with different type size (on riscv)

Emanuel Peter epeter at openjdk.org
Wed May 28 09:29:56 UTC 2025


On Tue, 20 May 2025 19:39:30 GMT, Hamlin Li <mli at openjdk.org> wrote:

> Hi,
> Can you help to review this patch?
> This pr is splited from https://github.com/openjdk/jdk/pull/25341, and contains only share code change.
> 
> This patch enable the vectorization of statement like `fd_1 bop fd_2 ? res_1 : res_2` in a loop.
> 
> The current behaviour on other platforms support vecatorization of `fd_1 bop fd_2 ? res_1 : res_2` in a loop only when `fd` and `res` have the same size, but this constraint seems not necessary at least not necessary on riscv, so I relax this constraint on riscv, maybe on other platforms it can be relaxed too, but currently I only made it work on riscv.
> Besides of this, I also relax the constraint on transforming Op_CMoveI/L to Op_VectorBlend on riscv, this bring some extra benefit when the `res` is not float or double types.
> Both relaxation bring performance benefit via vectorization.
> 
> Compared with other runs (master, master with `-XX:+UseVectorCmov -XX:+UseCMoveUnconditionally` turned on, patch without flags turned on), average improvement introduced by the patch with `-XX:+UseVectorCmov -XX:+UseCMoveUnconditionally` turned on is more than 2.1 times, in some cases it can bring more than 4 times improvement.
> When `-XX:-UseVectorCmov -XX:-UseCMoveUnconditionally` turned off, there is no regression on average.
> 
> Check more details at: https://github.com/openjdk/jdk/pull/25341.
> 
> Thanks

src/hotspot/cpu/riscv/matcher_riscv.hpp line 204:

> 202:   static bool supports_vectorize_cmove_bool_unconditionally() {
> 203:     return true;
> 204:   }

Does RISCV support the use of any input vector element type, including 8bit, 16bit, 32bit and 64bit masks, and any elements we would be blending, incl `byte, short, char, int, long, HF, F, D`?

Because it sounds you are promissing this really "unconditionally". Or what exactly do you mean by "unconditionally"?

src/hotspot/share/opto/superword.cpp line 2363:

> 2361:       VectorNode::is_vectorize_cmove_bool_unconditionally_supported()) {
> 2362:     return true;
> 2363:   }

Can you please list which additional cases this now allows?
I suppose `D/F` comparison for the `Bool`, and then `D/F` inputs for `CMove`, but we can mismatch, e.g. compare `F` but blend `D`, right?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25336#discussion_r2111380138
PR Review Comment: https://git.openjdk.org/jdk/pull/25336#discussion_r2111384982


More information about the hotspot-compiler-dev mailing list