RFR: 8278114: New addnode ideal optimization: converting "x + x" into "x << 1" [v8]

Zhiqiang Zang duke at openjdk.java.net
Sun Dec 19 20:30:24 UTC 2021


On Sun, 19 Dec 2021 01:46:06 GMT, Zhiqiang Zang <duke at openjdk.java.net> wrote:

>> A new ideal optimization can be introduced for addnode: converting "x + x" into "x << 1".
>> 
>> 
>> // Convert "x + x" into "x << 1"
>> if (in1 == in2) {
>>   return new LShiftINode(in1, phase->intcon(1));
>> }
>
> Zhiqiang Zang has updated the pull request incrementally with one additional commit since the last revision:
> 
>   clean microbenchmark.

Thank you very much! I adapt the microbenmark according to your advice and I am able to observed a notable difference now! 

I ran `make test TEST="micro:LShiftIdeal_XPlusX_LShiftC" MICRO="JAVA_OPTIONS=-Djmh.blackhole.mode=COMPILER" CONF_NAME="cov"` and this is the result:

Baseline:

Benchmark                             Mode  Cnt  Score   Error  Units
AddIdeal_XPlusX_LShiftC.baselineInt   avgt   60  1.457 ± 0.006  ns/op
AddIdeal_XPlusX_LShiftC.baselineLong  avgt   60  1.453 ± 0.004  ns/op
AddIdeal_XPlusX_LShiftC.testInt       avgt   60  2.521 ± 0.010  ns/op
AddIdeal_XPlusX_LShiftC.testLong      avgt   60  2.518 ± 0.009  ns/op


Patch:

Benchmark                             Mode  Cnt  Score   Error  Units
AddIdeal_XPlusX_LShiftC.baselineInt   avgt   60  1.455 ± 0.005  ns/op
AddIdeal_XPlusX_LShiftC.baselineLong  avgt   60  1.453 ± 0.005  ns/op
AddIdeal_XPlusX_LShiftC.testInt       avgt   60  1.455 ± 0.006  ns/op
AddIdeal_XPlusX_LShiftC.testLong      avgt   60  1.677 ± 0.005  ns/op


> As you can see for these kinds of microbenchmarks the cost of calling functions dominates the cost of the actual transformation, you can mitigate this by pulling the helper method out to be the benchmark (I don't see the reason to have a separate helper method, either), and putting the operation in a loop that has the results being sunk in a compiler blackhole (full blackhole or a non-inlined sink method won't work as effective in this case simply because it is also a function call) in each iteration.

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

PR: https://git.openjdk.java.net/jdk/pull/6675


More information about the hotspot-compiler-dev mailing list