RFR: 8371534: C2: Missed Ideal optimization opportunity with AndL and URShiftL

Benoît Maillard bmaillard at openjdk.org
Tue Nov 11 16:36:16 UTC 2025


On Mon, 10 Nov 2025 15:35:29 GMT, Tobias Hartmann <thartmann at openjdk.org> wrote:

>> This PR addresses a 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 `(x & mask) >> shift` into `(x >> shift) & (mask >> shift)`, where `mask` is a constant, for `URShiftL` and `URShiftI` nodes. This transformation is handled in `URShiftLNode::Ideal` and `URShiftINode::Ideal`. [JDK-8361700](https://bugs.openjdk.org/browse/JDK-8361700) addressed the analog case for `RShiftL` and `RShiftI`, but lacked the notification for unsigned shifting.
>> 
>> This PR builds on top of [JDK-8361700](https://bugs.openjdk.org/browse/JDK-8361700) and adds the following changes:
>> - Fix the notification mechanism in `add_users_of_use_to_worklist`
>> - Add the `URShiftL` in `TestMaskAndRShiftReorder.java`
>> - Drive-by changes: simplify the `RShiftL` test case slightly, and add the missing analog case for `RShiftI`
>> 
>> 
>> I tried to reproduce the missing optimization for the `URShiftI` without success. There must be some subtle difference with the `long` case that causes the optimization to be triggered in this specific setup. I still added the case to the fix in `add_users_of_use_to_worklist`, as there are likely cases where the notification is missing (but I was just not able to find one).
>> 
>> ### 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!
>
> That looks good to me. Thanks for quickly jumping on this!

Thank you for the reviews @TobiHartmann @mhaessig!

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

PR Comment: https://git.openjdk.org/jdk/pull/28218#issuecomment-3517770121


More information about the hotspot-compiler-dev mailing list