RFR: 8342095: Add autovectorizer support for subword vector casts [v13]

Jasmine Karthikeyan jkarthikeyan at openjdk.org
Fri Jan 23 06:28:08 UTC 2026


On Thu, 15 May 2025 13:15:05 GMT, Emanuel Peter <epeter at openjdk.org> wrote:

>> Jasmine Karthikeyan has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Check for AVX2 for byte/long conversions
>
>> This is a good point, while testing I experimented with patterns like this:
>> 
>> ```java
>> private static short[] testSubwordVector(short[] out, int[] in) {
>>     for (int i = 0; i < 512; i++) {
>>         out[i] = (short) (((short) in[i]) + (short) in[i]);
>>     }
>> 
>>     return out;
>> }
>> ```
>> 
>> The IR it produces looks like: `StoreC(AddI(RShiftI(LShiftI(LoadI, 16), 16)`. The same thing happens for sign extension as well. I didn't investigate too deeply, but I think the shifts prevent this pattern from vectorizing. The shifts are needed in the scalar IR since we don't have a `AddS` node, but in the future, when translating the IR to the vector graph we could convert the shift pattern into a `VectorCastX2Y` node as well.
> 
> I suppose there are 2 options here, when vectorizing:
> - Cast between `short <-> int`, do the add in `int`.
> - Somehow detect that this is an "`AddS`" in the type analysis phase of SuperWord. And then hack the graph so that we do not need the shifts. This would be more complicated, but might give us better results in the end.
> 
> Is there already an RFE for this? If not, would you mind filing one?

Hi @eme64, I apologize for the long delay, but I have some more time to work on this! I've merged from master, updated the tests, and addressed the previous code review concerns. I would love to know what you think!

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

PR Comment: https://git.openjdk.org/jdk/pull/23413#issuecomment-3788515264


More information about the hotspot-compiler-dev mailing list