RFR: 8278857: C2: optimize (x << 2) & -4 to x (and similar patterns) -> KnownBits for LShift [v2]
Quan Anh Mai
qamai at openjdk.org
Mon Mar 2 04:51:21 UTC 2026
On Mon, 2 Mar 2026 04:39:34 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:
>> 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.
>
> src/hotspot/share/utilities/intn_t.hpp line 181:
>
>> 179: // of the underlying storage rather than the logical type width. So we
>> 180: // instead compute the number of 1s in the maximum value.
>> 181: static_assert(!std::is_signed<T>::value, "type_width requires an unsigned type");
>
> `std::is_signed` is `false` for `intn_t`, you need to manually check that `T(-1) > T(0)`.
Adding a template `HotSpotNumerics::is_signed` is a good idea, too.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29898#discussion_r2870481515
More information about the hotspot-dev
mailing list