RFR: 8350896: Integer/Long.compress gets wrong type from CompressBitsNode::Value [v7]

Quan Anh Mai qamai at openjdk.org
Tue May 6 09:02:18 UTC 2025


On Mon, 5 May 2025 14:21:07 GMT, Jatin Bhateja <jbhateja at openjdk.org> wrote:

>> Hi All,
>> 
>> This bugfix patch fixes incorrect value computation for Integer/Long. compress APIs.
>> 
>> Problems occur with a constant input and variable mask where the input's value is equal to the lower bound of the mask value., In this case, an erroneous value range estimation results in a constant value. Existing value routine first attempts to constant fold the compression operation if both input and compression mask are constant values; otherwise, it attempts to constrain the value range of result based on the upper and lower bounds of mask type.
>> 
>> New IR test covers the issue reported in the bug report along with a case for value range based logic pruning.
>> 
>> Kindly review and share your feedback.
>> 
>> Best Regards,
>> Jatin
>
> Jatin Bhateja has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Adding additional test

src/hotspot/share/opto/intrinsicnode.cpp line 302:

> 300:       // res.hi = MIN(res.hi, (1L << result_bit_width) - 1)
> 301:       hi = src_type->hi_as_long() >= 0 ? src_type->hi_as_long() : hi;
> 302:       hi = result_bit_width < mask_bit_width ? MIN2((jlong)((1L << result_bit_width) - 1L), hi) : hi;

Note that if `result_bit_width == 63`, this computation will do `min_jlong - 1` which is UB.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23947#discussion_r2075035508


More information about the hotspot-compiler-dev mailing list