RFR: 8278857: C2: optimize (x << 2) & -4 to x (and similar patterns) -> KnownBits for LShift [v2]
Ashay Rane
duke at openjdk.org
Fri Feb 27 19:43:03 UTC 2026
> This PR contains the first of the two changes necessary to resolve
> JDK-8278857.
>
> The commit message, pasted below, has additional details.
>
>> Augment `RangeInference` with information about left shifts
>>
>> Add `RangeInference::infer_lshift()` to compute type information for
>> left shift operations. This method tracks known zero bits in the low
>> positions (the bottom `shift` bits are always zero after a left shift)
>> and computes signed and unsigned range bounds when the shift does not
>> cause overflow.
>>
>> This is the first of the two changes necessary to resolve JDK-8278857.
>> The second change will build on top of these changes to enable AND nodes
>> to be optimized away when the bits that would have been cleared by the
>> AND operation were already known to be zero.
Ashay Rane has updated the pull request incrementally with one additional commit since the last revision:
Addressed review comments
1. Elided redundant check when type is known to not be `Type::BOTTOM`.
2. Used `RangerInference` to AND the shift amount with 31 or 63 (based
on the basic type) to match the Java shift semantics so that we have
a higher chance of triggering the optimization.
3. Added a `type_width()` function that can work with `uintn_t<N>`
types, in addition to other unsigned types like `juint` and `julong`.
4. Updated `RangeInference::infer_lshift()` to now accept masked shift,
which works correctly because the caller (`LShiftINode::Ideal()`)
ANDs the shift amount with 31 or 63.
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/29898/files
- new: https://git.openjdk.org/jdk/pull/29898/files/14a9df86..3d366e42
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=29898&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=29898&range=00-01
Stats: 38 lines in 4 files changed: 27 ins; 3 del; 8 mod
Patch: https://git.openjdk.org/jdk/pull/29898.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/29898/head:pull/29898
PR: https://git.openjdk.org/jdk/pull/29898
More information about the hotspot-dev
mailing list