RFR: 8261008: Optimize Xor [v2]

Eric Liu github.com+10482586+therealeliu at openjdk.java.net
Thu Mar 4 10:11:07 UTC 2021


> 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

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/2776/files
  - new: https://git.openjdk.java.net/jdk/pull/2776/files/7e1588c1..fd25d5b4

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=2776&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=2776&range=00-01

  Stats: 20 lines in 2 files changed: 9 ins; 2 del; 9 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2776.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2776/head:pull/2776

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


More information about the hotspot-compiler-dev mailing list