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

Tobias Hartmann thartmann at openjdk.org
Wed Nov 12 13:52:07 UTC 2025


On Wed, 12 Nov 2025 07:49:42 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!
>
> 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>

Marked as reviewed by thartmann (Reviewer).

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

PR Review: https://git.openjdk.org/jdk/pull/28237#pullrequestreview-3453552960


More information about the hotspot-compiler-dev mailing list