Integrated: 8371558: C2: Missing optimization opportunity in AbsNode::Ideal
Benoît Maillard
bmaillard at openjdk.org
Thu Nov 13 09:28:09 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)
> - [x] tier1-4, plus some internal testing
>
> Thank you for reviewing!
This pull request has now been integrated.
Changeset: 9d6a61fd
Author: Benoît Maillard <bmaillard at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/9d6a61fda6f43577ee8f19483e5b47100ff8eec0
Stats: 95 lines in 2 files changed: 95 ins; 0 del; 0 mod
8371558: C2: Missing optimization opportunity in AbsNode::Ideal
Reviewed-by: thartmann, rcastanedalo, chagedorn
-------------
PR: https://git.openjdk.org/jdk/pull/28237
More information about the hotspot-compiler-dev
mailing list