RFR: 8342095: Add autovectorizer support for subword vector casts [v6]
Emanuel Peter
epeter at openjdk.org
Fri Feb 21 06:44:57 UTC 2025
On Mon, 17 Feb 2025 05:14:00 GMT, Jasmine Karthikeyan <jkarthikeyan at openjdk.org> wrote:
>> Hi all,
>> This patch adds initial support for the autovectorizer to generate conversions between subword types. Currently, when superword sees two packs that have different basic types, it discards them and bails out of vectorization. This patch changes the behavior to ask the backend if a cast between the conflicting types is supported, and keeps the pack if it is. Later, when the `VTransform` graph is built, a synthetic cast is emitted when packs requiring casts are detected. Currently, only narrowing casts are supported as I wanted to re-use existing `VectorCastX2Y` logic for the initial version, but adding more conversions is simple and can be done with a subsequent RFE. I have attached a JMH benchmark and got these results on my Zen 3 machine:
>>
>>
>> Baseline Patch
>> Benchmark (SIZE) Mode Cnt Score Error Units Score Error Units Improvement
>> VectorSubword.intToByte 1024 avgt 12 200.049 ± 19.787 ns/op 56.228 ± 3.535 ns/op (3.56x)
>> VectorSubword.intToShort 1024 avgt 12 179.826 ± 1.539 ns/op 43.332 ± 1.166 ns/op (4.15x)
>> VectorSubword.shortToByte 1024 avgt 12 245.580 ± 6.150 ns/op 29.757 ± 1.055 ns/op (8.25x)
>>
>>
>> I've also added some IR tests and they pass on my linux x64 machine. Thoughts and reviews would be appreciated!
>
> Jasmine Karthikeyan has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains six additional commits since the last revision:
>
> - Merge branch 'master' into vectorize-subword
> - Address comments from review, refactor test
> - Add new conversions to benchmark
> - Fix some tests that now vectorize
> - Implement widening and address comments from review
> - Subword vectorization
I had another quick look, and have some additional questions :)
src/hotspot/cpu/aarch64/matcher_aarch64.hpp line 203:
> 201: static bool is_vector_cast_supported(BasicType from_bt, BasicType to_bt) {
> 202: return false;
> 203: }
Do these simply not exist, or do you just want to leave that to a future RFE so someone else can take care of this?
src/hotspot/cpu/x86/matcher_x86.hpp line 264:
> 262: }
> 263:
> 264: static bool is_vector_cast_supported(BasicType from_bt, BasicType to_bt) {
Why does this not live next to `Matcher::match_rule_supported_vector`, would that not be a better fit?
src/hotspot/share/opto/superwordVTransformBuilder.cpp line 194:
> 192:
> 193: // If the use and def types are different, emit a cast node
> 194: if (use_bt != def_bt && !p0->is_Convert() && Matcher::is_vector_cast_supported(def_bt, use_bt)) {
The usual way we check if a vector instruction is implemented is to use `VectorNode::implemented`. Ah, actually there is a `VectorCastNode::implemented`. Why are you not using that one?
-------------
PR Review: https://git.openjdk.org/jdk/pull/23413#pullrequestreview-2632120544
PR Review Comment: https://git.openjdk.org/jdk/pull/23413#discussion_r1964928232
PR Review Comment: https://git.openjdk.org/jdk/pull/23413#discussion_r1964929822
PR Review Comment: https://git.openjdk.org/jdk/pull/23413#discussion_r1964934017
More information about the hotspot-compiler-dev
mailing list