RFR: 8347365: C2: Fix the handling of depends_only_on_test [v3]

Quan Anh Mai qamai at openjdk.org
Fri Jan 23 18:08:43 UTC 2026


> Hi,
> 
> This PR fixes the handling of `depends_only_on_test` when the control graph is transformed. It has to do with the theoretical idea of `depends_only_on_test`, copy from the JBS issue description:
> 
> To start with, what is `depends_only_on_test`? Given a node `n` with the control input `c`, if `c` can be deduced from `c'` and `n->depends_only_on_test() == true`, then we can rewire the control input of `n` to `c'`. This means that `depends_only_on_test` does not mean that the node depends on a test, it means that the node depends on the test that is its control input.
> 
> For example:
> 
>     if (y != 0) {
>         if (x > 0) {
>             if (y != 0) {
>                 x / y;
>             }
>         }
>     }
> 
> Then `x/y` `depends_only_on_test` because its control input is the test `y != 0`. Then, we can rewire the control input of the division to the outer `y != 0`, resulting in:
> 
>     if (y != 0) {
>         x / y;
>         if (x > 0) {
>         }
>     }
> 
> On the other hand, consider this case:
> 
>     if (x > 0) {
>         if (y != 0) {
>             if (x > 0) {
>                 x / y;
>             }
>         }
>     }
> 
> Then `x/y` does not `depends_only_on_test` because its control input is the test `x > 0` which is unrelated, we can see that if we rewire the division to the outer `x > 0` test, the division floats above the actual test `y != 0`. This means that `depends_only_on_test` is a dynamic property of a node, and not a static property of the division operation. It can change when we transform the graph and it can be different for different nodes of the same kind.
> 
> More details can be found in the description of `Node::depends_only_on_test` and `Node::pin_node_under_control` in this change.
> 
> Please take a look and leave your reviews, thanks a lot.

Quan Anh Mai 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 five additional commits since the last revision:

 - Merge branch 'master' into dependsonlyontest
 - Add IR test
 - more clarification
 - Refine comments
 - Fix depends_only_on_test

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/29158/files
  - new: https://git.openjdk.org/jdk/pull/29158/files/899d89f3..511c3f84

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=29158&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=29158&range=01-02

  Stats: 54484 lines in 1043 files changed: 33969 ins; 11266 del; 9249 mod
  Patch: https://git.openjdk.org/jdk/pull/29158.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/29158/head:pull/29158

PR: https://git.openjdk.org/jdk/pull/29158


More information about the hotspot-compiler-dev mailing list