JDK-8325674 : Constant fold across compares
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 23
  • Priority: P5
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2024-02-12
  • Updated: 2024-02-19
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.
Other
tbdUnresolved
Related Reports
Relates :  
Description
For example:

`x + 1 < 2` -> `x < 2 - 1`

If we can prove that `x + 1` does not overflow and `2 - 1` does not overflow.

Consider this more practical example:

```
public void foo(int[] arr) {
  for (i = arr.length - 1; i >= 0; --i) {
    blackhole(arr[i]);
  }
}
```

C2 emits a loop guard that looks `arr.length - 1 < 0`. We know `arr.length - 1` does not overflow because `arr.length` is positive. We can fold the comparison into `arr.length < 1`. We have to compute `arr.length - 1` computation if we enter the loop anyway, but we can avoid the subtraction computation if we exit the loop. I believe the simplification can also help with stronger integer range analysis in https://bugs.openjdk.org/browse/JDK-8275202.
Comments
A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/17853 Date: 2024-02-14 19:35:34 +0000
14-02-2024