Integrated: 8371534: C2: Missed Ideal optimization opportunity with AndL and URShiftL
Benoît Maillard
bmaillard at openjdk.org
Tue Nov 11 16:36:17 UTC 2025
On Mon, 10 Nov 2025 15:23:25 GMT, Benoît Maillard <bmaillard 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!
This pull request has now been integrated.
Changeset: f5eacbeb
Author: Benoît Maillard <bmaillard at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/f5eacbeb5fc58c1bd844d709fe92621ce3689d78
Stats: 35 lines in 2 files changed: 27 ins; 1 del; 7 mod
8371534: C2: Missed Ideal optimization opportunity with AndL and URShiftL
Reviewed-by: thartmann, mhaessig
-------------
PR: https://git.openjdk.org/jdk/pull/28218
More information about the hotspot-compiler-dev
mailing list