RFR: 8279607: Existing optimization "~x+1" -> "-x" can be generalized to "~x+c" -> "(c-1)-x". [v2]

Tobias Hartmann thartmann at openjdk.java.net
Tue Jan 11 07:19:29 UTC 2022


On Fri, 7 Jan 2022 17:48:56 GMT, Zhiqiang Zang <duke at openjdk.java.net> wrote:

>> Hi all,
>> 
>> Existing optimization `~x+1 -> -x` can be generalized to `~x+c -> (c-1)-x`. I included both microbenchmark and jtreg tests.
>> 
>> 
>> // Convert (~x+c) into (c-1)-x. Note there isn't a bitwise not
>> // bytecode, "~x" would typically represented as "x^(-1)", so (~x+c)
>> // will be (x^(-1))+c.
>> if (op1 == Op_Xor(bt) &&
>>     (in2->Opcode() == Op_ConI || in2->Opcode() == Op_ConL) &&
>>     phase->type(in1->in(2)) == TypeInteger::minus_1(bt)) {
>>   Node* c_minus_one = phase->makecon(add_ring(phase->type(in(2)), TypeInteger::minus_1(bt)));
>>   return SubNode::make(c_minus_one, in1->in(1), bt);
>> }
>> 
>> 
>> Thank you for reviewing.
>
> Zhiqiang Zang has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 16 commits:
> 
>  - Merge branch 'master'.
>  - include bug id for the test.
>  - Merge branch 'master'.
>  - fix copyright year.
>  - update copyright year to 2022.
>  - update copyright year.
>  - update benchmark.
>  - Merge branch 'master' of https://github.com/openjdk/jdk into addnode-PAddSub1202
>  - update microbenchmark.
>  - replace normal jtreg test with ir test.
>  - ... and 6 more: https://git.openjdk.java.net/jdk/compare/4243f4c9...5c9bcfd8

Isn't the same applicable to the corresponding `XoINode` and `XorLNode` optimizations?

https://github.com/openjdk/jdk/blob/126328cb6218a93d23ed6169d7e52fb2719528ed/src/hotspot/share/opto/addnode.cpp#L877-L883

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

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


More information about the hotspot-compiler-dev mailing list