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

Kangcheng Xu kxu at openjdk.org
Thu Feb 6 23:34:46 UTC 2025


[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.

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

Commit messages:
 - remove UseNewCode
 - Merge branch 'master' into arithmetic-canonicalization
 - fix serial addition regression
 - remove trailing empty comments
 - fix comment grammar
 - remove matching power-of-2 subtractions since it's already handled by Identity()
 - verify results with custom test methods
 - update comments to be more descriptive, remove unused can_reshape argument
 - update comments, use explicit opcode comparisons for LShift nodes
 - extract pattern matching to separate functions
 - ... and 35 more: https://git.openjdk.org/jdk/compare/a0c7f661...92100991

Changes: https://git.openjdk.org/jdk/pull/23506/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=23506&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8347555
  Stats: 455 lines in 3 files changed: 455 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/23506.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/23506/head:pull/23506

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


More information about the hotspot-compiler-dev mailing list