RFR: 8371558: C2: Missing optimization opportunity in AbsNode::Ideal
Christian Hagedorn
chagedorn at openjdk.org
Wed Nov 12 06:39:05 UTC 2025
On Tue, 11 Nov 2025 14:42:43 GMT, Benoît Maillard <bmaillard at openjdk.org> wrote:
> 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!
Looks good, thanks!
-------------
Marked as reviewed by chagedorn (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/28237#pullrequestreview-3451836082
More information about the hotspot-compiler-dev
mailing list