Integrated: 8261008: Optimize Xor

Eric Liu github.com+10482586+therealeliu at openjdk.java.net
Sat Mar 6 08:57:10 UTC 2021


On Mon, 1 Mar 2021 09:36:37 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.

This pull request has now been integrated.

Changeset: 23ee60d1
Author:    Eric Liu <eric.c.liu at arm.com>
Committer: Vladimir Kozlov <kvn at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/23ee60d1
Stats:     33 lines in 2 files changed: 32 ins; 0 del; 1 mod

8261008: Optimize Xor

Reviewed-by: thartmann, kvn

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

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


More information about the hotspot-compiler-dev mailing list