RFR: 8356760: VectorAPI: Optimize VectorMask.fromLong for all-true/all-false cases [v3]

Jatin Bhateja jbhateja at openjdk.org
Fri Jul 4 06:05:41 UTC 2025


On Thu, 3 Jul 2025 07:10:22 GMT, erifan <duke at openjdk.org> wrote:

>> If the input long value `l` of `VectorMask.fromLong(SPECIES, l)` would set or unset all lanes, `VectorMask.fromLong(SPECIES, l)` is equivalent to `maskAll(true)` or `maskAll(false)`. But the cost of `maskAll` is relative smaller than that of `fromLong`. This patch does the conversion for these cases if `l` is a compile time constant.
>> 
>> And this conversion also enables further optimizations that recognize maskAll patterns, see [1].
>> 
>> Some JTReg test cases are added to ensure the optimization is effective.
>> 
>> I tried many different ways to write a JMH benchmark, but failed. Since the input of `VectorMask.fromLong(SPECIES, l)` needs to be a specific compile-time constant, the statement will be hoisted out of the loop. If we don't use a loop, the hotspot will become other instructions, and no obvious performance change was observed. However, combined with the optimization of [1], we can observe a performance improvement of about 7% on both aarch64 and x64.
>> 
>> The patch was tested on both aarch64 and x64, all of tier1 tier2 and tier3 tests passed.
>> 
>> [1] https://github.com/openjdk/jdk/pull/24674
>
> erifan has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Simplify the test code

src/hotspot/share/opto/vectorIntrinsics.cpp line 707:

> 705:     elem_bt = converted_elem_bt;
> 706:     bits = gvn().longcon((bits_type->get_con() & 1L) == 0L ? 0L : -1L);
> 707:   } else if (!arch_supports_vector(opc, num_elem, elem_bt, checkFlags, true /*has_scalar_args*/)) {

I think it's appropriate to make this change as part of VectorLongToMaskNode::Ideal routine to give the opportunity for this transformation during the Iterative GVN pass.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25793#discussion_r2184478552


More information about the hotspot-compiler-dev mailing list