RFR: 8051725: Improve expansion of Conv2B nodes in the middle-end [v6]

Quan Anh Mai qamai at openjdk.org
Fri Apr 28 06:01:53 UTC 2023


On Tue, 25 Apr 2023 14:43:23 GMT, Jasmine Karthikeyan <jkarthikeyan at openjdk.org> wrote:

>> Hi, I've created optimizations for the expansion of `Conv2B` nodes, especially when followed immediately by an xor of 1. This pattern is fairly common, and can arise from both [cmov idealization](https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/movenode.cpp#L241) and [diamond-phi optimization](https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/cfgnode.cpp#L1571). This change replaces `Conv2B` nodes in the middle-end during post loop opts IGVN with conditional moves on supported platforms (x86_64, aarch64, arm32), allowing the bit flip with `xor` to be subsumed with an inversion of the comparison instead. This change also reduces the overhead of the matcher in the backends, as fewer rules need to be traversed in order to match an ideal node. Performance results from my (Zen 2) machine:
>> 
>> 
>>                                     Baseline                           Patch              Improvement
>> Benchmark                      Mode  Cnt  Score    Error Units     Score    Error  Units
>> Conv2BRules.testEquals0        avgt   10  47.566 ± 0.346 ns/op  /  34.130 ± 0.177  ns/op  + 28.2%
>> Conv2BRules.testNotEquals0     avgt   10  37.167 ± 0.211 ns/op  /  34.185 ± 0.258  ns/op  + 8.0%
>> Conv2BRules.testEquals1        avgt   10  35.059 ± 0.280 ns/op  /  34.847 ± 0.160  ns/op  (unchanged)
>> Conv2BRules.testEqualsNull     avgt   10  56.768 ± 2.600 ns/op  /  34.330 ± 0.625  ns/op  + 39.5%
>> Conv2BRules.testNotEqualsNull  avgt   10  47.447 ± 1.193 ns/op  /  34.142 ± 0.303  ns/op  + 28.0%
>> 
>> Reviews would be greatly appreciated!
>> 
>> Testing: tier1-2 on linux x64, GHA
>
> Jasmine Karthikeyan has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 11 commits:
> 
>  - Merge branch 'master' into conv2b-x86-lowering
>  - Whitespace tweak
>  - Make transform conditional
>  - Remove Conv2B from backend as it's macro expanded now
>  - Re-work transform to happen in macro expansion
>  - Fix whitespace and add bug tag to IR test
>  - Merge branch 'master' into conv2b-x86-lowering
>  - Merge branch 'master' into conv2b-x86-lowering
>  - Merge branch 'master' into conv2b-x86-lowering
>  - Merge branch 'master' into conv2b-x86-lowering
>  - ... and 1 more: https://git.openjdk.org/jdk/compare/bad6aa68...295b9a67

src/hotspot/share/opto/addnode.cpp line 890:

> 888:   }
> 889: 
> 890:   // Try to convert (c ? 1 : 0) ^ 1 into !c ? 1 : 0. This pattern can occur after expansion of Conv2B nodes.

Be more general? `Xor (CMove cond, iftrue, iffalse), op == CMove cond, (Xor iftrue op), (Xor iffalse op)`. You can be conservative and apply this only if `op`, `iftrue` and `iffalse` are all constant.

src/hotspot/share/opto/cfgnode.cpp line 1576:

> 1574:   Node *n = new Conv2BNode(cmp->in(1));
> 1575:   if( flipped )
> 1576:   n = new XorINode( phase->transform(n), phase->intcon(1) );

This lives under the `if (flipped)`, maybe move into a block for more clarity.

src/hotspot/share/opto/macro.cpp line 44:

> 42: #include "opto/macro.hpp"
> 43: #include "opto/memnode.hpp"
> 44: #include "opto/movenode.hpp"

Unnecessary change?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13345#discussion_r1179955624
PR Review Comment: https://git.openjdk.org/jdk/pull/13345#discussion_r1179953289
PR Review Comment: https://git.openjdk.org/jdk/pull/13345#discussion_r1179952045


More information about the hotspot-compiler-dev mailing list