RFR: 8372302: C2: IGVN verification fails because ModXNode::Ideal creates unused intermediate nodes
Benoît Maillard
bmaillard at openjdk.org
Wed Dec 10 08:55:23 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!
-------------
Commit messages:
- Update bug number format
- Fix style
- Add reduced test and fix
Changes: https://git.openjdk.org/jdk/pull/28488/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28488&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8372302
Stats: 70 lines in 2 files changed: 63 ins; 4 del; 3 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