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

Jasmine Karthikeyan jkarthikeyan at openjdk.org
Wed Jun 4 04:28:39 UTC 2025


On Wed, 28 May 2025 07:33:36 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> Jasmine Karthikeyan has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Reformat, add comments and char tests
>
> src/hotspot/share/opto/superword.cpp line 2553:
> 
>> 2551:             const Type* vt = vtn;
>> 2552:             int op = in->Opcode();
>> 2553:             if (!can_subword_truncate(in)) {
> 
> It seems `can_subword_truncate` does not cover `VectorNode::is_shift_opcode`, is that correct? Maybe we are missing IR tests that catch this, scary!

In this case since the condition is negated, the old condition should still be true since it falls through to the `return false` at the end of the function. Previously, it checked for a small list of nodes as requiring truncation handling which allows nodes that were not whitelisted to slip through and produce incorrect code. Now, we check for a larger group of nodes that we know do not need handling for truncation, so that any nodes not whitelisted will still produce valid code, but will not vectorize (until #23413).

> test/hotspot/jtreg/compiler/vectorization/TestSubwordTruncation.java line 64:
> 
>> 62: 
>> 63:     // Shorts
>> 64: 
> 
> Suggestion:
> 
> 
> Nit: you don't have a similar comment for other types, so just drop it here too ;)

Further in the file I used `// Bytes` to separate the byte methods, as well as the new char methods I added in the new commit. I think it helps navigating the file at a glance, at least in my emacs editor :)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25440#discussion_r2125606868
PR Review Comment: https://git.openjdk.org/jdk/pull/25440#discussion_r2125607475


More information about the hotspot-compiler-dev mailing list