RFR: 8356760: VectorAPI: Optimize VectorMask.fromLong for all-true/all-false cases [v3]
erifan
duke at openjdk.org
Thu Jul 10 08:08:43 UTC 2025
On Mon, 7 Jul 2025 09:08:37 GMT, Jatin Bhateja <jbhateja at openjdk.org> wrote:
>>> What if during iterative GVN a constant -1 seeps through IR graph and gets connected to the input of VectorLongToMaskNode, you won't be able to create maskAll true in that case?
>>
>> Yes, this PR doesn't support this case. Maybe we should do this optimization in `ideal`. If `VectorLongToMask` is not supported, then try to convert it to `maskAll` or `Replicate` in intrinsic.
>>
>>> Do you see any advantage of doing this at intrinsic layer over entirely handling it in Java implimentation by simply modifying the opcode of fromBitsCoerced to MODE_BROADCAST from existing MODE_BITS_COERCED_LONG_TO_MASK for 0 or -1 input.
>>
>> I had tried this method and gave it up, because it has up to 34% performance regression for specific cases on x64.
>
>> > What if during iterative GVN a constant -1 seeps through IR graph and gets connected to the input of VectorLongToMaskNode, you won't be able to create maskAll true in that case?
>>
>> Yes, this PR doesn't support this case. Maybe we should do this optimization in `ideal`. If `VectorLongToMask` is not supported, then try to convert it to `maskAll` or `Replicate` in intrinsic.
>>
>
> I would suggest extending VectorLongToMaskNode::Ideal for completeness of the solution.
OK. But in order to cover various cases, the implementation may be a bit troublesome. The solution I thought of is to **check whether the architecture supports VectorLongToMask, MaskAll and Replicate in `LibraryCallKit::inline_vector_frombits_coerced`. If it does, generate VectorLongToMask, and then convert it to MaskAll or Replicate in IGVN**. This is similar to the current implementation of vector rotate.
At the same time, this conversion may affect some other optimizations, such as `VectorMaskToLong(VectorLongToMask (x)) => x` and `VectorStoreMask(VectorLoadMask (x)) => x`. So we also need to fix these effects.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25793#discussion_r2196930141
More information about the hotspot-compiler-dev
mailing list