RFR: 8347555: [REDO] C2: implement optimization for series of Add of unique value [v7]
Kangcheng Xu
kxu at openjdk.org
Thu Mar 13 17:18:57 UTC 2025
On Thu, 13 Mar 2025 08:03:10 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> Kangcheng Xu has updated the pull request incrementally with one additional commit since the last revision:
>>
>> add micro benchmark
>
> src/hotspot/share/opto/addnode.cpp line 407:
>
>> 405: }
>> 406:
>> 407: // Try to convert a serial of additions into a single multiplication. Also convert `(a * CON) + a` to `(CON + 1) * a` as
>
> What about `(a * CON1) + (a * CON2)`? Like `11 * a + 5 * a`. Do we also optimize that?
`AddNode::IdealIL` handles to more general associative patterns like `(a*b) + (a*c)` into `a*(b + c)`
> src/hotspot/share/opto/addnode.cpp line 413:
>
>> 411: // power-of-2 addition (e.g., 3 * a => (a << 2) + a). Without this check, GVN would keep trying to optimize the same
>> 412: // node and can't progress. For example, 3 * a => (a << 2) + a => 3 * a => (a << 2) + a => ...
>> 413: if (find_power_of_two_addition_pattern(this, bt, nullptr) != nullptr) {
>
> Where does the optimization `3 * a => (a << 2) + a` happen? Do we use `find_power_of_two_addition_pattern` there too? If not: how do we prevent the code of the two locations from diverging in the future?
This `3 * a => (a << 2) + a` happens in `MulINode::Ideal()` and is independent from my code. My code does not explicitly produce power of two patterns but simple multiplication nodes, but such a multiplication node will be later idealized into power of two's.
Power of two patterns make my code more complex, but this is out of my control.
> how do we prevent the code of the two locations from diverging in the future?
I don't expect primitive opts like power-of-two being removed. Even if it does, `find_simple_multiplication_pattern()` will still work.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23506#discussion_r1993987750
PR Review Comment: https://git.openjdk.org/jdk/pull/23506#discussion_r1993984743
More information about the hotspot-compiler-dev
mailing list