Skip to content

8380424: C2: Fix missing identity optimization for vector nodes#30529

Open
erifan wants to merge 1 commit intoopenjdk:pr/28313from
erifan:JDK-8380424-miss-identity-opt
Open

8380424: C2: Fix missing identity optimization for vector nodes#30529
erifan wants to merge 1 commit intoopenjdk:pr/28313from
erifan:JDK-8380424-miss-identity-opt

Conversation

@erifan
Copy link
Copy Markdown
Contributor

@erifan erifan commented Apr 1, 2026

Ideal and Identity optimizations require all input nodes of the IR pattern to be ready for the optimization to take effect. However, node generation in the incremental inlining phase is unordered, so sometimes downstream nodes in the IR pattern are generated before upstream nodes, causing Ideal or Identity optimizations to miss. If no subsequent process triggers the optimization again, the optimization misses forever.

Vector nodes (especially generated by VectorAPI) are often wrapped using VectorBoxNode during generation, and the existence of these box nodes and unbox nodes further hinders the matching of IR optimization patterns. The -XX:VerifyIterativeGVN option allows us to check which IGVN optimizations are missed; however, currently, the verification for Vector nodes is skipped. Enabling the Identity optimization check for vector nodes shows that many tests fail, as shown below.

jdk/incubator/vector/ByteVector128LoadStoreTests.java
jdk/incubator/vector/ByteVector256LoadStoreTests.java
jdk/incubator/vector/ByteVector512LoadStoreTests.java
jdk/incubator/vector/ByteVector64LoadStoreTests.java
jdk/incubator/vector/ByteVectorMaxLoadStoreTests.java
jdk/incubator/vector/ShortVector128LoadStoreTests.java
jdk/incubator/vector/ShortVector256LoadStoreTests.java
jdk/incubator/vector/ShortVector512LoadStoreTests.java
jdk/incubator/vector/ShortVector64LoadStoreTests.java
jdk/incubator/vector/ShortVectorMaxLoadStoreTests.java
jdk/incubator/vector/Vector512ConversionTests.java
jdk/incubator/vector/Vector64ConversionTests.java#id0
jdk/incubator/vector/VectorMaxConversionTests.java#id0

They are caused by the missed optimizations of AndVNode::Identity() and ShiftVNode::Identity(). And from JDK-8370863, we know that VectorStoreMaskNode::Identity() may miss as well.

To recover these potential missed optimizations, we need to trigger them again at appropriate points. Currently, a GVN optimization runs once during node generation, and if no subsequent changes are made, the node will not be added to the IGVN worklist to trigger IGVN optimization again. Therefore, the corresponding nodes need to be added to the IGVN worklist at appropriate points.

Many phases affect the shape of the node tree, but inlining and boxing have a particularly significant impact on vector nodes. After PhaseVector, inlining is complete, and vector boxing/unboxing has been eliminated. At this point, the node tree is fully materialized, with no additional interfering nodes. Therefore, this PR adds all nodes to the IGVN worklist at this point to recover potentially missed GVN optimizations.

However, this modification still cannot handle the situation after PhaseVector, so this PR also enhances the notification of multi-hop IR optimization patterns in add_users_of_use_to_worklist.

With this PR, the above test failures passed in 100 tests, so this PR enables identity optimization verification for vector nodes. We expect that with this PR, there will be very few cases of Vector identity optimization misses; if they do occur, we should fix them rather than skip them.

This PR does not enable Ideal optimization verification for vector nodes because the inputs of some commutative nodes may be swapped in Ideal, causing changes in the hash value, which could lead to verification failure.

We also found many test failures caused by the missing of ShenandoahLoadReferenceBarrierNode::Identity(). This PR skipped the identity verification of the ShenandoahLoadReferenceBarrierNode because it was not investigated in this PR.

This PR tested all tier1 to tier3 jtreg tests on aarch64 (sve, neon) and x64 (avx3, avx2) platforms using options -ea -esa -XX:-TieredCompilation -XX:CompileThreshold=100 -XX:VerifyIterativeGVN=1110, and repeated the test 100 times for the aforementioned error cases. All tests passed.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Integration blocker

 ⚠️ Dependency #28313 must be integrated first

Issue

  • JDK-8380424: C2: Fix missing identity optimization for vector nodes (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30529/head:pull/30529
$ git checkout pull/30529

Update a local copy of the PR:
$ git checkout pull/30529
$ git pull https://git.openjdk.org/jdk.git pull/30529/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30529

View PR using the GUI difftool:
$ git pr show -t 30529

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30529.diff

Using Webrev

Link to Webrev Comment

Ideal and Identity optimizations require all input nodes of the IR
pattern to be ready for the optimization to take effect. However, node
generation in the incremental inlining phase is unordered, so sometimes
downstream nodes in the IR pattern are generated before upstream nodes,
causing Ideal or Identity optimizations to miss. If no subsequent
process triggers the optimization again, the optimization misses forever.

Vector nodes (especially generated by VectorAPI) are often wrapped using
`VectorBoxNode` during generation, and the existence of these box nodes
and unbox nodes further hinders the matching of IR optimization patterns.
The `-XX:VerifyIterativeGVN` option allows us to check which IGVN
optimizations are missed; however, currently, the verification for Vector
nodes is skipped. Enabling the Identity optimization check for vector
nodes shows that many tests fail, as shown below.
```
jdk/incubator/vector/ByteVector128LoadStoreTests.java
jdk/incubator/vector/ByteVector256LoadStoreTests.java
jdk/incubator/vector/ByteVector512LoadStoreTests.java
jdk/incubator/vector/ByteVector64LoadStoreTests.java
jdk/incubator/vector/ByteVectorMaxLoadStoreTests.java
jdk/incubator/vector/ShortVector128LoadStoreTests.java
jdk/incubator/vector/ShortVector256LoadStoreTests.java
jdk/incubator/vector/ShortVector512LoadStoreTests.java
jdk/incubator/vector/ShortVector64LoadStoreTests.java
jdk/incubator/vector/ShortVectorMaxLoadStoreTests.java
jdk/incubator/vector/Vector512ConversionTests.java
jdk/incubator/vector/Vector64ConversionTests.java#id0
jdk/incubator/vector/VectorMaxConversionTests.java#id0
```
They are caused by the missed optimizations of `AndVNode::Identity()`
and `ShiftVNode::Identity()`. And from JDK-8370863, we know that
`VectorStoreMaskNode::Identity()` may miss as well.

To recover these potential missed optimizations, we need to trigger them
again at appropriate points. Currently, a GVN optimization runs once
during node generation, and if no subsequent changes are made, the node
will not be added to the IGVN worklist to trigger IGVN optimization
again. Therefore, the corresponding nodes need to be added to the IGVN
worklist at appropriate points.

Many phases affect the shape of the node tree, but inlining and boxing
have a particularly significant impact on vector nodes. After
`PhaseVector`, inlining is complete, and vector boxing/unboxing has been
eliminated. At this point, the node tree is fully materialized, with no
additional interfering nodes. Therefore, this PR adds all nodes to the
IGVN worklist at this point to recover potentially missed GVN
optimizations.

However, this modification still cannot handle the situation after
`PhaseVector`, so this PR also enhances the notification of multi-hop
IR optimization patterns in `add_users_of_use_to_worklist`.

With this PR, the above test failures passed in 100 tests, so this PR
enables identity optimization verification for vector nodes. We expect
that with this PR, there will be very few cases of Vector identity
optimization misses; if they do occur, we should fix them rather than
skip them.

This PR does not enable `Ideal` optimization verification for vector
nodes because the inputs of some commutative nodes may be swapped in
`Ideal`, causing changes in the hash value, which could lead to
verification failure.

We also found many test failures caused by the missing of
`ShenandoahLoadReferenceBarrierNode::Identity()`. This PR skipped the
identity verification of the `ShenandoahLoadReferenceBarrierNode`
because it was not investigated in this PR.

This PR tested all tier1 to tier3 jtreg tests on aarch64 (sve, neon) and
x64 (avx3, avx2) platforms using options `-ea -esa -XX:-TieredCompilation
-XX:CompileThreshold=100 -XX:VerifyIterativeGVN=1110`, and repeated the
test 100 times for the aforementioned error cases. All tests passed.
@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Apr 1, 2026

👋 Welcome back erfang! A progress list of the required criteria for merging this PR into pr/28313 will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 1, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Apr 1, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 1, 2026

@erifan The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 1, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge bot commented Apr 1, 2026

Webrevs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-compiler hotspot-compiler-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

1 participant