RFR: 8281453: New optimization: convert `~x` into `-1-x` when `~x` is used in an arithmetic expression [v9]
Zhiqiang Zang
duke at openjdk.org
Thu Sep 29 20:52:41 UTC 2022
On Wed, 28 Sep 2022 09:20:43 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:
>> @merykitty Sounds good! I'm implementing this in XorNode.
>>
>> I came a question on `outcnt()`, I included in `XorINode::Ideal`
>>
>> if (phase->type(in2) == TypeInt::MINUS_1) {
>> std::cerr << "!!!outcnt() = " << outcnt() << std::endl;
>> if (outcnt() == 1) {
>> int user_op = unique_out()->Opcode();
>> if (user_op == Op_AddI || user_op == Op_SubI) {
>> return new SubINode(in2, in1);
>> }
>> }
>> }
>>
>> but I found tests failed, for example
>>
>> @Test
>> @IR(failOn = {IRNode.SUB, IRNode.XOR, IRNode.ADD})
>> // Checks -1 - ~x => x
>> public int test25(int x) {
>> return -1 - ~x;
>> }
>>
>> After some debugging, I found the cause was `outcnt()` is `0` so the transformation did not happen at all (the IR printed stills follows the original structure of `-1-~x`). I don't understand why `outcnt()` is `0` not `1` since `~x` is used by `-1 - ~x`. Appreciate it if you can shed some light on this. Thank you.
>
> @CptGit It is due to the fact that GVN runs as soon as the frontend parses the code, during which the graph is incomplete, and you get `outcnt() == 0` because the uses of the node have not been parsed yet. You can defer the transformation to IGVN, which happens later. Thanks.
@merykitty I removed the use check. Does it look good to you? I did not include test `(x + y) & ~(x + y) => 0` because I found we do not have such idealization in `AndINode` because even `x & ~x => 0` is not supported.
-------------
PR: https://git.openjdk.org/jdk/pull/7376
More information about the hotspot-compiler-dev
mailing list