RFR: 8347555: [REDO] C2: implement optimization for series of Add of unique value [v3]
Kangcheng Xu
kxu at openjdk.org
Thu Feb 27 18:17:25 UTC 2025
On Thu, 27 Feb 2025 16:14:22 GMT, Kangcheng Xu <kxu at openjdk.org> wrote:
>> [JDK-8347555](https://bugs.openjdk.org/browse/JDK-8347555) is a redo of [JDK-8325495](https://bugs.openjdk.org/browse/JDK-8325495) was [first merged](https://git.openjdk.org/jdk/pull/20754) then backed out due to a regression. This patch redos the feature and fixes the bit shift overflow problem. For more information please refer to the previous PR.
>>
>> When constanlizing multiplications (possibly in forms on `lshifts`), the multiplier is upgraded to long and then later narrowed to int if needed. However, when a `lshift` operand is exactly `32`, overflowing an int, using long has an unexpected result. (i.e., `(1 << 32) = 1` and `(int) (1L << 32) = 0`)
>>
>> The following was implemented to address this issue.
>>
>> if (UseNewCode2) {
>> *multiplier = bt == T_INT
>> ? (jlong) (1 << con->get_int()) // loss of precision is expected for int as it overflows
>> : ((jlong) 1) << con->get_int();
>> } else {
>> *multiplier = ((jlong) 1 << con->get_int());
>> }
>>
>>
>> Two new bitshift overflow tests were added.
>
> Kangcheng Xu has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 49 commits:
>
> - Merge branch 'master' into arithmetic-canonicalization
> - added bit shift operations accept an explicit BasicType
> - use explicit argument types for overloaded java_shift_left()
> - use java_shift_left()
> - remove UseNewCode
> - Merge branch 'master' into arithmetic-canonicalization
> - fix serial addition regression
> - remove trailing empty comments
> - fix comment grammar
>
> Co-authored-by: Christian Hagedorn <christian.hagedorn at oracle.com>
> - remove matching power-of-2 subtractions since it's already handled by Identity()
> - ... and 39 more: https://git.openjdk.org/jdk/compare/8323ddfe...0ffae804
Added `java_shift_left(jlong, jint, BasicType bt)` (and `java_shift_right(...)`, `java_shift_right_unsigned(...)` for the sake of consistency). All tests are passing.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/23506#issuecomment-2688734241
More information about the hotspot-compiler-dev
mailing list