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
On Thu, 26 Feb 2026 17:23:38 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.
>
> Thanks for extracting this into a separate PR, it will be much clearer for us to review and much less overwhelming for you to address all of the comments :)
@merykitty Thanks for taking a look and for your suggestions. The code is so much cleaner now and I learnt a number of things related to the type system. I've added a new commit that incorporates your suggestions, but let me know if you'd like to see more changes. Thanks!
-------------
PR Comment: https://git.openjdk.org/jdk/pull/29898#issuecomment-3974732615
More information about the hotspot-dev
mailing list