RFR: 8325495: C2: implement optimization for series of Add of unique value
Kangcheng Xu
kxu at openjdk.org
Wed Aug 28 22:57:48 UTC 2024
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.
-------------
Commit messages:
- add more IR tests
- update comments of existing tests
- Merge branch 'master' into arithmetic-canonicalization
- add more IR tests
- add more IR tests
- distinguish AndNode from MulNode
- add initial IR unit tests
- passes all hotspot-compiler tests
- implement arithmetic canonicalization for additions
Changes: https://git.openjdk.org/jdk/pull/20754/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=20754&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8325495
Stats: 316 lines in 5 files changed: 312 ins; 0 del; 4 mod
Patch: https://git.openjdk.org/jdk/pull/20754.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/20754/head:pull/20754
PR: https://git.openjdk.org/jdk/pull/20754
More information about the hotspot-compiler-dev
mailing list