RFR: 8261008: Optimize Xor
Tobias Hartmann
thartmann at openjdk.java.net
Mon Mar 1 10:43:48 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.
Just wondering, why is `x ^ x` special? Shouldn't we then also optimize `x - x`, `x | x` and others?
-------------
PR: https://git.openjdk.java.net/jdk/pull/2776
More information about the hotspot-compiler-dev
mailing list