RFR: 8261008: Optimize Xor [v2]

Vladimir Kozlov kvn at openjdk.java.net
Thu Mar 4 19:34:55 UTC 2021


On Thu, 4 Mar 2021 10:11:07 GMT, Eric Liu <github.com+10482586+theRealELiu at openjdk.org> wrote:

>> This patch canonicalizes 'Xor' to constant zero when both inputs are the
>> same.
>> 
>> It's not quite easy to measure the performance change between 'xor' and
>> constant zero, the later is typically a single 'mov' in generated code.
>> But given by this transformation, c2 may perform some other more
>> powerful optimizations.
>> 
>> This was tested with the micro benchmark below. Loop in this case is
>> properly removed and the performance increases significantly.
>> 
>> public void xorTheSame(MyState s, Blackhole bh) {
>>   int x = s.in1;
>>   int y = s.in2;
>>   for (int i = 0; i < 5000; i++) {
>>     y = x ^ x;
>>     x = y ^ y;
>>   }
>>   bh.consume(x);
>> }
>> 
>> [Test]
>> All jtreg tests passed without new failure.
>
> Eric Liu has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Implements Value() for XorNode.
>   
>   Change-Id: Ic9fc01375801adc82c0a0289d9a11a5367031eb4

Good.

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

Marked as reviewed by kvn (Reviewer).

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


More information about the hotspot-compiler-dev mailing list