RFR: 8347555: [REDO] C2: implement optimization for series of Add of unique value [v7]
Kangcheng Xu
kxu at openjdk.org
Mon May 5 18:15:54 UTC 2025
On Tue, 29 Apr 2025 16:42:41 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> Hello @eme64. I pinged you in [an in-line review](https://github.com/openjdk/jdk/pull/23506#discussion_r2042974649). Could you please provide some commons on this assertion? This is currently blocking my progress and breaking the build. Thank you very much!
>
> @tabjy Thanks for your patience, this one took me longer than I wanted. I responded like this above:
>
>> 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.
@eme64
> I still think that the patterns covered are more limited than preferable. [...] can we recognize patterns like this: a + (a << CON)?
I only aimed to cover cases minimally needed for `a + a + ... + a` at fear of adding even more complexity. Cases like `CON * a + a` are considered unintended side-effects due to the way pattern matching is implemented. Flipped LHS and RHS like `a + (a << CON)` is not recognized (by me or `IdealIL()`).
That is, I only match the RHS being a base variable (i.e., `a`). I understand you think giving the effort, we could explore more opportunities here. To explain the complexity, consider the following expression with base variable `a`:
a + a + ((a + a) + a)
^ LHS(a) = RHS(a)
= 2*a + ((a + a) + a)
^ unable to resolve RHS to 3*a without some recursion
I could, at very least, try to swap LHS and RHS if no match is found, but the case above will still not benefit from swapping (without a recursive algorithm). Simpler cases like `a + (a << CON)` might.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/23506#issuecomment-2851911494
More information about the hotspot-compiler-dev
mailing list