RFR: 8325495: C2: implement optimization for series of Add of unique value [v2]
Kangcheng Xu
kxu at openjdk.org
Wed Sep 18 20:42:41 UTC 2024
On Tue, 17 Sep 2024 09:37:31 GMT, Roland Westrelin <roland at openjdk.org> wrote:
>> Kangcheng Xu has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 22 additional commits since the last revision:
>>
>> - Merge branch 'openjdk:master' into arithmetic-canonicalization
>> - Merge pull request #1 from tabjy/arithmetic-canonicalization-v2
>>
>> Arithmetic canonicalization v2
>> - remove dead code
>> - fix potential void type const nodes
>> - refactor and cleanup
>> - add more test cases
>> - re-implement depth limit on recursion
>> - passes TestIRLShiftIdeal_XPlusX_LShiftC
>> - passes AddI[L]NodeIdealizationTests
>> - revert depth limits
>> - ... and 12 more: https://git.openjdk.org/jdk/compare/72ec1422...c8fdb74c
>
> src/hotspot/share/opto/addnode.cpp line 427:
>
>> 425: }
>> 426:
>> 427: Node* con = (bt == T_INT) ? (Node*) phase->intcon((jint) factor) : (Node*) phase->longcon(factor);
>
> You can use `integercon()` and pass `bt`
I disagree: `integercon()` internally uses `checked_cast<jint>(l)` to make prevent information loss during type conversion and asserts at runtime if the value is larger what a `jint` can hold. However, such an information loss is intended for integer arithmetic overflows. (e.g., `Integer.MAX_VALUE * a + a` is extracted to `((jlong) Integer.MAX_VALUE + (jlong) 1) * a`. Here we want `Integer.MAX_VALUE + 1` to overflow to `(int) Integer.MIN_VALUE`).
If I were to use `integercon()`, the best I could do is `intgercon(bt == T_INT ? (jint) factor : factor)` which is rather pointless.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20754#discussion_r1765694385
More information about the hotspot-compiler-dev
mailing list