RFR: 8347555: [REDO] C2: implement optimization for series of Add of unique value [v9]
Kangcheng Xu
kxu at openjdk.org
Mon Apr 14 21:36:02 UTC 2025
On Thu, 10 Apr 2025 19:02:37 GMT, Kangcheng Xu <kxu at openjdk.org> wrote:
>> src/hotspot/share/opto/addnode.cpp line 415:
>>
>>> 413: if (find_power_of_two_addition_pattern(this, bt).valid) {
>>> 414: return nullptr;
>>> 415: }
>>
>> Hmm. So somewhere we would have generated that pattern, probably in MulNode. Can you add a verification there, to check that we are only generating patterns that `find_power_of_two_addition_pattern` recognizes? That would make sure that we keep the code here and there in sync.
>
> Added `assert()` to `Mul[IL]Node::Ideal()`
After experiment for a while, I found it not practical to assert power-of-2 patterns in `Ideal()` (or anywhere else).
https://github.com/openjdk/jdk/blob/e9b42dcce268f32bd2ec3c01ac6221073b888538/src/hotspot/share/opto/mulnode.cpp#L263-L266
First, `phase->transform()` could transform `LShiftINode`s into something very different. Second, there is no guarantee the `res = AddINode` will remain untransformed by the time it's passed into `find_power_of_two_addition_pattern()`. Asserting power-of-2 patterns before such transformation is not very helpful.
> @eme64: [...] check that we are only generating patterns that find_power_of_two_addition_pattern recognizes
In short, we can't guarantee we'll always pick up *transformed* power-of-2 patterns, at least not with significant effort and difficulty predicting all possible transformations. However, I would argue making this guarantee is outside the scope of this issue as all serial addition patterns are correctly picked up and optimized right now.
I'm not sure how to proceed with this. Please let me know what you think. Thanks!
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23506#discussion_r2042974649
More information about the hotspot-compiler-dev
mailing list