RFR: 8291600: [vectorapi] vector cast op check is not always needed for vector mask cast [v3]

Xiaohong Gong xgong at openjdk.org
Thu Aug 25 03:22:34 UTC 2022


On Thu, 25 Aug 2022 03:02:54 GMT, Jie Fu <jiefu at openjdk.org> wrote:

>> Xiaohong Gong has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Fix x86 codegen issue
>
> src/hotspot/share/opto/vectornode.cpp line 1628:
> 
>> 1626:             // directly. This could avoid the transformation ordering issue from
>> 1627:             // "VectorStoreMask (VectorLoadMask vmask) => vmask".
>> 1628:             return new VectorMaskCastNode(value, vmask_type);
> 
> Why do you change this code?
> Is it a must to enable this optimization?

For a vector mask unbox operation, if the input is a `VectorBox`, and the boxed value type is not equal to the unbox type, we need to do the type casting. Originally, we separate the type casting for two different cases:
1. if the vector element size in bytes is equal (e.g. casting between `int` and `float`), the conversion is:

  VectorUnbox (VectorBox vmask) ==> VectorMaskCast (vmask)

This doesn't need to emit any instructions.

2. otherwise (e.g. casting from `short` to `int`), the conversion is:

  VectorUnbox (VectorBox vmask) ==> VectorLoadMask (VectorStoreMask vmask)

This means we need to convert the short mask vector back to a boolean vector, and then casting the boolean vector to a int vector (i.e. `S->B->I`). 

With the new changes in this PR, `VectorMaskCast` supports the vector mask casting for all cases and all platforms (originally it only supports the first case for most platforms), we can implement the second cases simply with `VectorMaskCast`. That means we can optimize `S->B->I` to `S->I`. This saves the unnecessary narrowing and extending instructions due to the temporary boolean vector result.

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

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


More information about the hotspot-compiler-dev mailing list