RFR: 8371558: C2: Missing optimization opportunity in AbsNode::Ideal [v2]

Benoît Maillard bmaillard at openjdk.org
Wed Nov 12 07:49:42 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, zero)`, which ends up calling `add_users_to_worklist(phi)`, and `add_users_of_use_to_worklist(phi, zero, ...)`. 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!

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

  Update test/hotspot/jtreg/compiler/c2/TestMissingOptAbsZeroMinusX.java
  
  Co-authored-by: Tobias Hartmann <tobias.hartmann at oracle.com>

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/28237/files
  - new: https://git.openjdk.org/jdk/pull/28237/files/9df620da..83077987

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

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 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