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

Emanuel Peter epeter at openjdk.org
Tue Apr 29 16:44:53 UTC 2025


On Mon, 14 Apr 2025 21:32:47 GMT, Kangcheng Xu <kxu at openjdk.org> wrote:

>> 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!

Hmm, ok I see. Why don't you remove the asserts for now, and we see how clear the code looks now. I think I asked for the consistency check because I was confused by the previous code structure. Maybe it is ok now as it is.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23506#discussion_r2066951920


More information about the hotspot-compiler-dev mailing list