Integrated: 8350177: C2 SuperWord: Integer.numberOfLeadingZeros, numberOfTrailingZeros, reverse and bitCount have input types wrongly truncated for byte and short

Jasmine Karthikeyan jkarthikeyan at openjdk.org
Sun Jul 13 21:30:53 UTC 2025


On Mon, 26 May 2025 07:15:31 GMT, Jasmine Karthikeyan <jkarthikeyan at openjdk.org> wrote:

> Hi all,
> This patch fixes cases in SuperWord when compiling subword types where vectorized code would be given a narrower type than expected, leading to miscompilation due to truncation. This fix is a generalization of the same fix applied for `Integer.reverseBytes` in [JDK-8305324](https://bugs.openjdk.org/browse/JDK-8305324). The patch introduces a check for nodes that are known to tolerate truncation, so that any future cases of subword truncation will avoid creating miscompiled code.
> 
> The patch reuses the existing logic to set the type of the vectors to int, which currently disables vectorization for the affected patterns entirely. Once [JDK-8342095](https://bugs.openjdk.org/browse/JDK-8342095) is merged and automatic casting support is added the autovectorizer should automatically insert casts to and from int, maintaining correctness.
> 
> I've added an IR test that checks for correctly compiled outputs. Thoughts and reviews would be appreciated!

This pull request has now been integrated.

Changeset: 77bd417c
Author:    Jasmine Karthikeyan <jkarthikeyan at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/77bd417c9990f57525257d9df89b9df4d7991461
Stats:     464 lines in 2 files changed: 460 ins; 0 del; 4 mod

8350177: C2 SuperWord: Integer.numberOfLeadingZeros, numberOfTrailingZeros, reverse and bitCount have input types wrongly truncated for byte and short

Reviewed-by: epeter, thartmann

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

PR: https://git.openjdk.org/jdk/pull/25440


More information about the hotspot-compiler-dev mailing list