RFR: 8322077: Add Ideal transformation: (~a) | (~b) => ~(a & b) [v4]
Emanuel Peter
epeter at openjdk.org
Fri Jan 5 16:25:27 UTC 2024
On Fri, 15 Dec 2023 23:35:56 GMT, Zhiqiang Zang <duke at openjdk.org> wrote:
>> Hello,
>>
>> (~a) | (~b) => ~(a & b) is a widely seen pattern, for example it is implemented for LLVM [here](https://github.com/llvm/llvm-project/blob/397f1ce9efb4eea1ee10fe4833f733b8c7abd878/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp#L1617C28-L1617C28); however it is missing in current implementation of hotspot. This pull request adds this transformation and associated tests.
>>
>> Thanks.
>
> Zhiqiang Zang has updated the pull request incrementally with one additional commit since the last revision:
>
> untabify.
Looks like a good idea. Left a few comments.
I would have merged this with https://github.com/openjdk/jdk/pull/16333, since it is essentially the symmetric case. But leave it separate now.
It would be nice to have some shared tests, where both optimizations need to be combined. Like:
`(~a | ~b) & (~c | ~d)` -> `~(a & b) & ~(c & d)` -> `~((a & b) | (c & d))`
src/hotspot/share/opto/addnode.cpp line 787:
> 785: }
> 786: return nullptr;
> 787: }
If you are going to use this also for your changes in https://github.com/openjdk/jdk/pull/16333, then you probably want this to go into a shared file.
src/hotspot/share/opto/addnode.cpp line 816:
> 814: return make_not(phase,
> 815: phase->transform(new AndINode(in(1)->in(1), in(2)->in(1))),
> 816: T_INT);
I'd put the `AndI` node on a separate line. Call it `add_a_b` or similar.
Then you can transform on the next line.
And then on a third line the `make_not`.
-------------
Changes requested by epeter (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/16334#pullrequestreview-1806238724
PR Review Comment: https://git.openjdk.org/jdk/pull/16334#discussion_r1443055241
PR Review Comment: https://git.openjdk.org/jdk/pull/16334#discussion_r1443052473
More information about the hotspot-compiler-dev
mailing list