RFR: 8371558: C2: Missing optimization opportunity in AbsNode::Ideal

Benoît Maillard bmaillard at openjdk.org
Tue Nov 11 14:57:24 UTC 2025


This PR addresses another missed optimization in `PhaseIterGVN` due to a missing notification to indirect users within `PhaseIterGVN::add_users_of_use_to_worklist`.

The affected optimization is the transformation of `abs(0-x)` into `abs(x)`. This transformation is implemented in `AbsNode::Ideal`.

The bug was found by the fuzzer. At some point during IGVN, we have the following setup:


Phi  ... 
 \  /
 SubI
  |
 AbsI


The `Phi` node gets folded into a `ConI`, and we call `replace_node(phi, con)`, which ends up calling `add_users_to_worklist(phi)`, and `add_users_of_use_to_worklist(phi, sub, ...)`. However the case for this specific notification was missing there, and the `AbsI` node is never notified (not added to the worklist).

This PR brings the following changes:
- Detect the optimization pattern in `add_users_of_use_to_worklist` for `AbsI`, `AbsL`, `AbsF` and `AbsD`
- Add new test `TestMissingOptAbsZeroMinusX.java`, initially obtained from the fuzzer and then heavily reduced, both with the usual tools and manually. In addition to `AbsI`, I have also added test cases for `AbsF` and `AbsD`, but was not able to reproduce for `AbsL` despite my best efforts.

### Testing
- [x] [GitHub Actions](https://github.com/benoitmaillard/jdk/actions?query=branch%3AJDK-8371534)
- [ ] tier1-4, plus some internal testing

Thank you for reviewing!

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

Commit messages:
 - Add cases for the different types and cleanup
 - Add reduced test
 - Add notification in PhaseIterGVN::add_users_of_use_to_worklist

Changes: https://git.openjdk.org/jdk/pull/28237/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28237&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8371558
  Stats: 95 lines in 2 files changed: 95 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/28237.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/28237/head:pull/28237

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


More information about the hotspot-compiler-dev mailing list