RFR: 8371603: C2: Missing Ideal optimizations for load and store vectors on SVE [v2]
Xiaohong Gong
xgong at openjdk.org
Fri Dec 5 09:37:22 UTC 2025
> **Problem:**
>
> This issue occurs on a 256-bit SVE machine, caused by the following problematic pattern in `LoadVectorNode::Ideal()`:
>
>
> Node* LoadVectorNode::Ideal(PhaseGVN* phase, bool can_reshape) {
> const TypeVect* vt = vect_type();
> if (Matcher::vector_needs_partial_operations(this, vt)) {
> return VectorNode::try_to_gen_masked_vector(phase, this, vt);
> }
> return LoadNode::Ideal(phase, can_reshape);
> }
>
>
> The condition `Matcher::vector_needs_partial_operations(this, vt)` returns true for `LoadVectorNode` with 256-bit vector size even when the vector size equals the maximum vector size on SVE. In such cases, when `VectorNode::try_to_gen_masked_vector()` returns `nullptr`, the method exits early without calling `LoadNode::Ideal()`. This results in missing crucial optimizations that would normally be applied by the superclass.
>
> This code was introduced by https://bugs.openjdk.org/browse/JDK-8286941 to generate vector masks for partial vector operations, but it failed to ensure that the superclass `Ideal()` method is always invoked when no transformation is applied.
>
> **Solution:**
>
> This patch addresses the issue through two changes:
>
> 1. Refine `Matcher::vector_needs_partial_operations()` to return true only when the vector node genuinely represents a partial vector operation that requires masking.
> 2. Modify `VectorNode::try_to_gen_masked_vector()` to never return `nullptr`, ensuring the superclass `Ideal()` method is always invoked when no transformation is applied.
>
> **Testing:**
>
> - Verified on different SVE platforms with different vector sizes (128|256|512 bits).
> - Verified on X86 platforms with different avx options (-XX:UseAVX=1|2|3).
> - Added two new IR tests to verify 1) previously missing optimizations for `LoadVector/StoreVector` are now applied, and 2) that mask and the correct IR patterns are generated for partial vector operations.
Xiaohong Gong has updated the pull request incrementally with one additional commit since the last revision:
Combine the condition check and IR transformation to a method
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/28651/files
- new: https://git.openjdk.org/jdk/pull/28651/files/ba7592cb..6206e8c0
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=28651&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=28651&range=00-01
Stats: 36 lines in 2 files changed: 9 ins; 8 del; 19 mod
Patch: https://git.openjdk.org/jdk/pull/28651.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/28651/head:pull/28651
PR: https://git.openjdk.org/jdk/pull/28651
More information about the hotspot-compiler-dev
mailing list