RFR: 8267687: ModXNode::Ideal optimization is better than Parse::do_irem

Nils Eliasson neliasso at openjdk.java.net
Mon May 31 14:20:23 UTC 2021


On Tue, 25 May 2021 15:34:44 GMT, Yi Yang <yyang at openjdk.org> wrote:

> Hi all,
> 
> Can I have a review of this change? I noticed there are two almost the same optimizations for % operation. For x%y, both Parse::do_irem and ModXNode::ideal are optimized for a special case that divisor y is `2^n` constant value.
> 
> ModXNode::Ideal opt:
> https://github.com/openjdk/jdk/blob/cc687fd43ade6be8760c559f3ffa909c5937727c/src/hotspot/share/opto/divnode.cpp#L112-L160
> 
> Parse::do_irem opt:
> https://github.com/openjdk/jdk/blob/cc687fd43ade6be8760c559f3ffa909c5937727c/src/hotspot/share/opto/parse2.cpp#L1171-L1196
> 
> It turns out that ModXNode::Ideal optimization is better than Parse::do_irem in a simple microbenchmark(Please check out JBS attachment for detailed benchmark result):
> 
> ModXNode::Ideal opt:
> ----------------
> Benchmark Mode Cnt Score Error Units
> ModPowerOf2.testNegativePowerOf2 avgt 25 8746.608 ± 139.777 ns/op
> ModPowerOf2.testPositivePowerOf2 avgt 25 8735.545 ± 86.145 ns/op
> 
> Parse::do_irem opt:
> ----------------
> Benchmark Mode Cnt Score Error Units
> ModPowerOf2.testNegativePowerOf2 avgt 25 8693.797 ± 7.844 ns/op
> ModPowerOf2.testPositivePowerOf2 avgt 25 6618.652 ± 1.739 ns/op
> 
> Diff for ideal graph:
> ----------------
> ![ideal_graph](https://user-images.githubusercontent.com/5010047/119525589-34585f80-bdb1-11eb-9d7e-e3962cd7f789.jpg)
> 
> Thanks!
> Yang

In general  - I like the change! Very good that the optimization is moved out of the parse stage and into the node.

On the choice of which optimization to keep - could you please post the generated assembly for both versions?

Also - what hardware did you benchmark on? Do you see the same result on different CPUs?

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

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


More information about the hotspot-compiler-dev mailing list