RFR: 8281518: New optimization: convert "(x|y)-(x^y)" into "x&y"
Quan Anh Mai
duke at openjdk.java.net
Wed Feb 9 16:04:49 UTC 2022
On Wed, 9 Feb 2022 00:44:08 GMT, Zhiqiang Zang <duke at openjdk.java.net> wrote:
> Convert `(x|y)-(x^y)` into `x&y`, in `SubINode::Ideal` and `SubLNode::Ideal`.
>
> The results of the microbenchmark are as follows:
>
> Baseline:
> Benchmark Mode Cnt Score Error Units
> SubIdeal_XOrY_Minus_XXorY_.baselineInt avgt 60 0.481 ± 0.003 ns/op
> SubIdeal_XOrY_Minus_XXorY_.baselineLong avgt 60 0.482 ± 0.004 ns/op
> SubIdeal_XOrY_Minus_XXorY_.testInt avgt 60 0.901 ± 0.007 ns/op
> SubIdeal_XOrY_Minus_XXorY_.testLong avgt 60 0.894 ± 0.004 ns/op
>
> Patch:
> Benchmark Mode Cnt Score Error Units
> SubIdeal_XOrY_Minus_XXorY_.baselineInt avgt 60 0.480 ± 0.003 ns/op
> SubIdeal_XOrY_Minus_XXorY_.baselineLong avgt 60 0.483 ± 0.005 ns/op
> SubIdeal_XOrY_Minus_XXorY_.testInt avgt 60 0.600 ± 0.004 ns/op
> SubIdeal_XOrY_Minus_XXorY_.testLong avgt 60 0.602 ± 0.004 ns/op
There is a large number of transformations in this bitwise operation family such as `(x & y) | (x ^ y) == x | y`, `(x & y) ^ (x | y) == x ^ y`, `(x ^ y) ^ (x | y) == x & y` , etc and that does not even touch operations involving 3 operands. It seems both gcc and clang perform these 2-operand bitwise transformations so you could look at them to see if there is a more general way to achieve all combinations.
Thanks.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7395
More information about the hotspot-compiler-dev
mailing list