Integrated: 8281453: New optimization: convert ~x into -1-x when ~x is used in an arithmetic expression
Zhiqiang Zang
duke at openjdk.org
Thu Oct 6 22:19:33 UTC 2022
On Tue, 8 Feb 2022 05:51:37 GMT, Zhiqiang Zang <duke at openjdk.org> wrote:
> Similar to `(~x)+c` -> `(c-1)-x` and `~(x+c)` -> `(-c-1)-x` in #6858, we can also introduce similar optimizations for subtraction, `c-(~x)` -> `x+(c+1)` and `~(c-x)` -> `x+(-c-1)`.
>
> To generalize, I convert `~x` into `-1-x` when `~x` is used only in arithmetic expression. For example, `c-(~x)` will be converted into `c-(-1-x)` which will match other pattern and will be transformed again in next iteration and finally become `x+(c+1)`.
>
> Also the conversion from `~x` into `-1-x` happens when `x` is an arithmetic expression itself. For example, `~(x+c)` will be transformed into `-1-(x+c)` and eventually `(-c-1)-x`.
>
> The results of the microbenchmark are as follows:
>
> Baseline:
> Benchmark Mode Cnt Score Error Units
> NotOpTransformation.baselineInt avgt 60 0.440 ± 0.002 ns/op
> NotOpTransformation.baselineLong avgt 60 0.440 ± 0.001 ns/op
> NotOpTransformation.testInt1 avgt 60 0.613 ± 0.006 ns/op
> NotOpTransformation.testInt2 avgt 60 0.868 ± 0.036 ns/op
> NotOpTransformation.testLong1 avgt 60 0.674 ± 0.008 ns/op
> NotOpTransformation.testLong2 avgt 60 0.698 ± 0.006 ns/op
>
> Patch:
> Benchmark Mode Cnt Score Error Units
> NotOpTransformation.baselineInt avgt 60 0.440 ± 0.001 ns/op
> NotOpTransformation.baselineLong avgt 60 0.440 ± 0.001 ns/op
> NotOpTransformation.testInt1 avgt 60 0.329 ± 0.001 ns/op
> NotOpTransformation.testInt2 avgt 60 0.329 ± 0.001 ns/op
> NotOpTransformation.testLong1 avgt 60 0.329 ± 0.001 ns/op
> NotOpTransformation.testLong2 avgt 60 0.329 ± 0.001 ns/op
This pull request has now been integrated.
Changeset: 5dd851d8
Author: Zhiqiang Zang <zhiqiang.zang at utexas.edu>
Committer: Vladimir Kozlov <kvn at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/5dd851d872c50ef33034c56007c58e6fa69ebd32
Stats: 957 lines in 7 files changed: 562 ins; 376 del; 19 mod
8281453: New optimization: convert ~x into -1-x when ~x is used in an arithmetic expression
Reviewed-by: kvn
-------------
PR: https://git.openjdk.org/jdk/pull/7376
More information about the hotspot-compiler-dev
mailing list