RFR: 8281453: New optimization: convert `~x` into `-1-x` when `~x` is used in an arithmetic expression [v12]
Quan Anh Mai
qamai at openjdk.org
Thu Sep 29 15:19:30 UTC 2022
On Thu, 29 Sep 2022 15:07:02 GMT, Zhiqiang Zang <duke at openjdk.org> wrote:
>> src/hotspot/share/opto/addnode.cpp line 891:
>>
>>> 889: if (is_used_in_only_arithmetic(this, T_INT)
>>> 890: // used only once and contains arithmetic
>>> 891: || (outcnt() == 1 && (in1->Opcode() == Op_AddI || in1->Opcode() == Op_SubI))) {
>>
>> May I ask why do you need `outcnt() == 1` here, thanks.
>
> I was thinking of which cases we still want to transform even when the `Xornode` is used in a non-arithmetic expression, and the only case I think safe to transform is that when it is used only once and has some arithmetic inside, for example,
> `return ~(x+c)`.
In that case, you would need to check the `Opcode` of the use similar to the above line. However, I believe that since you have already deferred the transformation, the bitwise transformations should have been finished by then so you don't need to worry about that. I would suggest adding a comment to remind this. And some tests to confirm, such as `(x + y) & ~(x + y) == 0`. Thanks.
-------------
PR: https://git.openjdk.org/jdk/pull/7376
More information about the hotspot-compiler-dev
mailing list