8380424: C2: Fix missing identity optimization for vector nodes#30529
Open
erifan wants to merge 1 commit intoopenjdk:pr/28313from
Open
8380424: C2: Fix missing identity optimization for vector nodes#30529erifan wants to merge 1 commit intoopenjdk:pr/28313from
erifan wants to merge 1 commit intoopenjdk:pr/28313from
Conversation
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.
|
👋 Welcome back erfang! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
VectorBoxNodeduring generation, and the existence of these box nodes and unbox nodes further hinders the matching of IR optimization patterns. The-XX:VerifyIterativeGVNoption 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.They are caused by the missed optimizations of
AndVNode::Identity()andShiftVNode::Identity(). And from JDK-8370863, we know thatVectorStoreMaskNode::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 inadd_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
Idealoptimization verification for vector nodes because the inputs of some commutative nodes may be swapped inIdeal, 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 theShenandoahLoadReferenceBarrierNodebecause 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
Integration blocker
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30529/head:pull/30529$ git checkout pull/30529Update a local copy of the PR:
$ git checkout pull/30529$ git pull https://git.openjdk.org/jdk.git pull/30529/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 30529View PR using the GUI difftool:
$ git pr show -t 30529Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30529.diff
Using Webrev
Link to Webrev Comment