RFR: 8279607: Existing optimization "~x+1" -> "-x" can be generalized to "~x+c" -> "(c-1)-x". [v4]

Zhiqiang Zang duke at openjdk.java.net
Sat Jan 15 21:44:55 UTC 2022


> Hi all,
> 
> Existing optimization `~x+1 -> -x` can be generalized to `~x+c -> (c-1)-x`. I included both microbenchmark and jtreg tests.
> 
> 
> // Convert (~x+c) into (c-1)-x. Note there isn't a bitwise not
> // bytecode, "~x" would typically represented as "x^(-1)", so (~x+c)
> // will be (x^(-1))+c.
> if (op1 == Op_Xor(bt) &&
>     (in2->Opcode() == Op_ConI || in2->Opcode() == Op_ConL) &&
>     phase->type(in1->in(2)) == TypeInteger::minus_1(bt)) {
>   Node* c_minus_one = phase->makecon(add_ring(phase->type(in(2)), TypeInteger::minus_1(bt)));
>   return SubNode::make(c_minus_one, in1->in(1), bt);
> }
> 
> 
> Thank you for reviewing.

Zhiqiang Zang has updated the pull request incrementally with one additional commit since the last revision:

  cast to jlong instead of long.

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/6858/files
  - new: https://git.openjdk.java.net/jdk/pull/6858/files/c540be30..4285a239

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=6858&range=03
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=6858&range=02-03

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk/pull/6858.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/6858/head:pull/6858

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


More information about the hotspot-compiler-dev mailing list