RFR: 8281453: New optimization: convert `~x` into `-1-x` when `~x` is used in an arithmetic expression [v13]

Zhiqiang Zang duke at openjdk.org
Thu Sep 29 19:44:08 UTC 2022


> 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 and `~x` has only a single user. 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.448 ± 0.002  ns/op
> NotOpTransformation.baselineLong  avgt   60  0.448 ± 0.002  ns/op
> NotOpTransformation.testInt1      avgt   60  0.615 ± 0.003  ns/op
> NotOpTransformation.testInt2      avgt   60  0.838 ± 0.004  ns/op
> NotOpTransformation.testLong1     avgt   60  0.671 ± 0.003  ns/op
> NotOpTransformation.testLong2     avgt   60  0.670 ± 0.003  ns/op
> 
> Patch:
> Benchmark                         Mode  Cnt  Score   Error  Units
> NotOpTransformation.baselineInt   avgt   60  0.451 ± 0.003  ns/op
> NotOpTransformation.baselineLong  avgt   60  0.447 ± 0.002  ns/op
> NotOpTransformation.testInt1      avgt   60  0.334 ± 0.002  ns/op
> NotOpTransformation.testInt2      avgt   60  0.334 ± 0.002  ns/op
> NotOpTransformation.testLong1     avgt   60  0.334 ± 0.002  ns/op
> NotOpTransformation.testLong2     avgt   60  0.335 ± 0.002  ns/op

Zhiqiang Zang has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 15 commits:

 - merge master.
 - remove redundant tests.
 - Use separate test classes for xor nodes.
 - move transformation to xornode and make it genealized.
 - include microbenchmark.
 - merge master.
 - merge master.
 - clean.
 - merge tests into XXXINodeIdealizationTests
 - clean.
 - ... and 5 more: https://git.openjdk.org/jdk/compare/aeef3ecd...bb904b5b

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

Changes: https://git.openjdk.org/jdk/pull/7376/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=7376&range=12
  Stats: 939 lines in 7 files changed: 544 ins; 376 del; 19 mod
  Patch: https://git.openjdk.org/jdk/pull/7376.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/7376/head:pull/7376

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


More information about the hotspot-compiler-dev mailing list