Integrated: 8325495: C2: implement optimization for series of Add of unique value

Kangcheng Xu kxu at openjdk.org
Wed Oct 9 15:11:12 UTC 2024


On Wed, 28 Aug 2024 19:27:29 GMT, Kangcheng Xu <kxu at openjdk.org> wrote:

> This pull request resolves [JDK-8325495](https://bugs.openjdk.org/browse/JDK-8325495) by converting series of additions of the same operand into multiplications. I.e., `a + a + ... + a + a + a => n*a`.
> 
> As an added benefit, it also converts `C * a + a` into `(C+1) * a` and `a << C + a` into `(2^C + 1) * a` (with respect to constant `C`). This is actually a side effect of IGVN being iterative: at converting the `i`-th addition, the previous `i-1` additions would have already been optimized to multiplication (and thus, further into bit shifts and additions/subtractions if possible).  
> 
> Some notable examples of this transformation include:
> - `a + a + a` => `a*3` => `(a<<1) + a`
> - `a + a + a + a` => `a*4` => `a<<2`
> - `a*3 + a` => `a*4` => `a<<2`
> - `(a << 1) + a + a` => `a*2 + a + a` => `a*3 + a` => `a*4 => a<<2`
> 
> See included IR unit tests for more.

This pull request has now been integrated.

Changeset: c30ad012
Author:    Kangcheng Xu <kxu at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/c30ad0124e7743f3a4c29ef901761f8fcc53de10
Stats:     414 lines in 3 files changed: 414 ins; 0 del; 0 mod

8325495: C2: implement optimization for series of Add of unique value

Reviewed-by: chagedorn, roland

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

PR: https://git.openjdk.org/jdk/pull/20754


More information about the hotspot-compiler-dev mailing list