While working on test cases for JDK-8373134 I discovered a missing optimisation for arithmetic or. Max node implementations get the Max(A, Max(A, B)) == Max(A, B) optimisation via MaxNode::find_identity_operation. However, this is not present for arithmetic or. E.g.
```
// int c = a * i; is going to optimize to c = a;
// So this effectively becomes (a | (b | a))
// Since (a | a) is a, it should be possible to
// reduce to (a | b)
private static int test(int b, int a)
{
int i;
for (i = -10; i < 1; i++)
{
}
int c = a * i;
return a | (b | c);
}
```
The above results in this IR nodes at the end of gvn. With the optimisation we should expect to find a single Or with 10 and 11.
```
114 OrI === _ 10 11 [[ 115 ]] !jvms: TestIntOr::test @ bci:21 (line 21)
115 OrI === _ 11 114 [[ 116 ]] !jvms: TestIntOr::test @ bci:22 (line 21)
```
```
// int c = a * i; is going to optimize to c = a;
// So this effectively becomes (a | (b | a))
// Since (a | a) is a, it should be possible to
// reduce to (a | b)
private static int test(int b, int a)
{
int i;
for (i = -10; i < 1; i++)
{
}
int c = a * i;
return a | (b | c);
}
```
The above results in this IR nodes at the end of gvn. With the optimisation we should expect to find a single Or with 10 and 11.
```
114 OrI === _ 10 11 [[ 115 ]] !jvms: TestIntOr::test @ bci:21 (line 21)
115 OrI === _ 11 114 [[ 116 ]] !jvms: TestIntOr::test @ bci:22 (line 21)
```
- relates to
-
JDK-8373134 C2: Min/Max users of Min/Max uses should be enqueued for GVN
-
- Open
-