JDK-8279607 : Existing optimization "~x+1" -> "-x" can be generalized to "~x+c" -> "(c-1)-x".
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 18
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2021-12-16
  • Updated: 2022-01-25
  • Resolved: 2022-01-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 19
19 masterFixed
Related Reports
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
Existing optimization `~x+1 -> -x` can be generalized to `~x+c -> (c-1)-x`. I included both microbenchmark and jtreg tests.

```cpp
// 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);
}
```

I have submitted a pull request https://github.com/openjdk/jdk/pull/6858



Comments
Changeset: 0bf95a1a Author: Zhiqiang Zang <zhiqiang.zang@utexas.edu> Committer: Tobias Hartmann <thartmann@openjdk.org> Date: 2022-01-20 07:38:04 +0000 URL: https://git.openjdk.java.net/jdk/commit/0bf95a1a7327cc4899863143e2dfdf3d87dbdf0c
20-01-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/6858 Date: 2021-12-16 00:02:12 +0000
07-01-2022

This is a PR https://github.com/openjdk/jdk/pull/6858 Moving it to JDK for further analysis.
07-01-2022