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

Quan Anh Mai duke at openjdk.java.net
Sun Dec 19 11:09: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.

The reason you don't see any shift instruction is that `x << 11 >>> 11` is transformed into `x & 0x1FFFFF` which is the instruction you see in `0x00007f97b9418dae:   and    $0x1fffff,%eax`.

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