Integrated: 8347555: [REDO] C2: implement optimization for series of Add of unique value

Kangcheng Xu kxu at openjdk.org
Fri Oct 10 14:07:47 UTC 2025


On Thu, 6 Feb 2025 23:29:51 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.

This pull request has now been integrated.

Changeset: f6d77cb3
Author:    Kangcheng Xu <kxu at openjdk.org>
Committer: Roland Westrelin <roland at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/f6d77cb33299ae0636a2b52ee752f27e9ea9191b
Stats:     875 lines in 6 files changed: 874 ins; 0 del; 1 mod

8347555: [REDO] C2: implement optimization for series of Add of unique value

Reviewed-by: roland, epeter

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

PR: https://git.openjdk.org/jdk/pull/23506


More information about the hotspot-compiler-dev mailing list