RFR: 8350177: C2 SuperWord: Integer.numberOfLeadingZeros, numberOfTrailingZeros, reverse and bitCount have input types wrongly turncated for byte and short [v4]

Jasmine Karthikeyan jkarthikeyan at openjdk.org
Wed Jun 18 04:02:36 UTC 2025


> 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!

Jasmine Karthikeyan has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:

 - Merge, address code review
 - Merge branch 'master' into vector-truncation
 - Add assert for unexpected node in truncation
 - Reformat, add comments and char tests
 - Fix vector truncation with subword types

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/25440/files
  - new: https://git.openjdk.org/jdk/pull/25440/files/e2ab39c4..ce16e2de

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=25440&range=03
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=25440&range=02-03

  Stats: 207689 lines in 3722 files changed: 125627 ins; 56108 del; 25954 mod
  Patch: https://git.openjdk.org/jdk/pull/25440.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/25440/head:pull/25440

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


More information about the hotspot-compiler-dev mailing list