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

Zhiqiang Zang duke at openjdk.org
Wed Sep 28 21:46:53 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 in an 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)`.
> 
> The results of the microbenchmark are as follows:
> 
> Baseline:                                                                                                                                         
> Benchmark                         Mode  Cnt  Score    Error  Units
> NotOpTransformation.baselineInt   avgt   60  0.439 ±  0.001  ns/op
> NotOpTransformation.baselineLong  avgt   60  0.439 ±  0.001  ns/op
> NotOpTransformation.testInt1      avgt   60  0.603 ±  0.001  ns/op
> NotOpTransformation.testInt2      avgt   60  0.603 ±  0.001  ns/op
> NotOpTransformation.testLong1     avgt   60  0.658 ±  0.001  ns/op
> NotOpTransformation.testLong2     avgt   60  0.658 ±  0.001  ns/op
> 
> Patch:
> Benchmark                         Mode  Cnt  Score    Error  Units
> NotOpTransformation.baselineInt   avgt   60  0.439 ±  0.001  ns/op
> NotOpTransformation.baselineLong  avgt   60  0.439 ±  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

Zhiqiang Zang has updated the pull request incrementally with one additional commit since the last revision:

  move transformation to xornode and make it genealized.

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/7376/files
  - new: https://git.openjdk.org/jdk/pull/7376/files/1c238b8d..ec3360d4

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=7376&range=09
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=7376&range=08-09

  Stats: 390 lines in 6 files changed: 225 ins; 104 del; 61 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