RFR: 8350177: C2 SuperWord: Integer.numberOfLeadingZeros, numberOfTrailingZeros, reverse and bitCount have input types wrongly turncated for byte and short
Jasmine Karthikeyan
jkarthikeyan at openjdk.org
Wed Jun 4 04:34:15 UTC 2025
On Wed, 28 May 2025 07:46:12 GMT, Emanuel Peter <epeter 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!
>
> And just for good measure: should we also add tests for `char`?
Thanks a lot for your review @eme64! I've pushed a commit that should address the reviews, and fix the GHA failures. I've added char tests as well. Regarding long operations, I don't think it's possible for this code path to encounter them. Earlier in the function, this logic is guarded with `vtn->basic_type() == T_INT` so I think only integer nodes need to be added to the list. Let me know what you think!
@chhagedorn Thanks for the reminder! It might be good to run some testing so that we can get it tested and reviewed before the RDP1 cutoff.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/25440#issuecomment-2938450410
More information about the hotspot-compiler-dev
mailing list