Details
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
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
Attachments
Issue Links
- relates to
-
JDK-8273021 C2: Improve Add and Xor ideal optimizations
-
- Resolved
-
-
JDK-8281453 New optimization: convert ~x into -1-x when ~x is used in an arithmetic expression
-
- Resolved
-