RFR: 8372302: C2: IGVN verification fails because ModXNode::Ideal creates unused intermediate nodes [v3]

Benoît Maillard bmaillard at openjdk.org
Fri Dec 12 19:05:15 UTC 2025


> This PR addresses a failure in IGVN verification with `ModI` and `ModL` nodes.
> 
> In `ModeXNode::Ideal`, we have code to optimize a modulo expression by expressing it in terms of other operations. There are actually two distinct cases, one where the divisor is a constant and is equal to `modulo 2^k-1` for some integer `k`, and a more general case where other transformations do not succeed. Because these transformations involve creating several new nodes (sometimes in a loop) and calling `phase->transform(...)` on them, we want to avoid accidentally triggering optimizations on the "unfinished" state of the subgraph. For this, we create a temporary dummy node and add edges to the nodes being constructed.
> 
> There are some execution paths where the node is not destroyed before `Ideal` returns, and this creates issues during IGVN verification, as the verification code checks if the number of nodes has changed after having called `Ideal` on a given node and not expecting changes.
> 
> The path in question is when we exit because the divisor is a constant and is the minimum value:
> https://github.com/openjdk/jdk/blob/c19b12927d2ac901ec8ccaa2de5897ee4c47af56/src/hotspot/share/opto/divnode.cpp#L1146-L1147
> 
> The zero case does not cause problems (this seems to be because it would hide behind a `div0_check` anyway).
> 
> The fix is simply to only create the temporary node when it is needed, and thus avoiding returning without destroying it.
> 
> ### Testing
> - [x] [GitHub Actions](TODO)
> - [x] tier1-4, plus some internal testing
> 
> Thank you for reviewing!

Benoît Maillard has updated the pull request incrementally with two additional commits since the last revision:

 - Update package
 - Move to compiler/c2/igvn

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/28488/files
  - new: https://git.openjdk.org/jdk/pull/28488/files/7d57f7ae..13758bef

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

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/28488.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/28488/head:pull/28488

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


More information about the hotspot-compiler-dev mailing list