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

Zhiqiang Zang duke at openjdk.org
Thu Sep 15 16:53:44 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)`.
> 
> The results of the microbenchmark are as follows:
> 
> Baseline:                                                                                                                                         
> Benchmark                        Mode  Cnt  Score   Error  Units
> SubIdealCMinusNotX.baselineInt   avgt   60  0.504 ± 0.011  ns/op
> SubIdealCMinusNotX.baselineLong  avgt   60  0.484 ± 0.004  ns/op
> SubIdealCMinusNotX.testInt1      avgt   60  0.779 ± 0.004  ns/op
> SubIdealCMinusNotX.testInt2      avgt   60  0.896 ± 0.004  ns/op
> SubIdealCMinusNotX.testLong1     avgt   60  0.722 ± 0.004  ns/op
> SubIdealCMinusNotX.testLong2     avgt   60  0.720 ± 0.005  ns/op
> 
> Patch:
> Benchmark                        Mode  Cnt  Score   Error  Units
> SubIdealCMinusNotX.baselineInt   avgt   60  0.487 ± 0.009  ns/op
> SubIdealCMinusNotX.baselineLong  avgt   60  0.486 ± 0.009  ns/op
> SubIdealCMinusNotX.testInt1      avgt   60  0.372 ± 0.010  ns/op
> SubIdealCMinusNotX.testInt2      avgt   60  0.365 ± 0.003  ns/op
> SubIdealCMinusNotX.testLong1     avgt   60  0.369 ± 0.004  ns/op
> SubIdealCMinusNotX.testLong2     avgt   60  0.399 ± 0.016  ns/op

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

  include microbenchmark.

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

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

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

  Stats: 98 lines in 1 file changed: 98 ins; 0 del; 0 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