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

Benoît Maillard bmaillard at openjdk.org
Mon Nov 10 15:33:21 UTC 2025


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::IdealIL` and `URShiftINode::IdealIL`. [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!

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

Commit messages:
 - Format
 - Add missing case in add_users_of_use_to_worklist
 - Update test and add testURShiftL case

Changes: https://git.openjdk.org/jdk/pull/28218/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28218&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8371534
  Stats: 35 lines in 2 files changed: 27 ins; 1 del; 7 mod
  Patch: https://git.openjdk.org/jdk/pull/28218.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/28218/head:pull/28218

PR: https://git.openjdk.org/jdk/pull/28218


More information about the hotspot-compiler-dev mailing list