JDK-8326001 : Reassociate binary operators for LongCountedLoops
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 23
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2024-02-15
  • Updated: 2025-10-07
  • Resolved: 2025-10-07
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
tbdResolved
Related Reports
Duplicate :  
Description
For example:

```
for (long i = 0; i < n; ++i) { foo(a + i + b); }
```
Can be reassociated to get
```
for (long i = 0; i < n; ++i) { foo(a + b + i); }
```

There is already reassociation code, but it is only applied to `CountedLoop`. `LongCountedLoop` is not a `CountedLoop` by inheritance. https://github.com/openjdk/jdk/blob/99c9ae127c0a3b8c4fc6ede87079ff7c693a2905/src/hotspot/share/opto/loopnode.cpp#L4772-L4777

This might have been regressed in JDK-8259609
The code is there already
Comments
Looks like a dup of JDK-8369258 which is currently already out for review - closing this as the dup accordingly.
07-10-2025

Optimizations for long counted loops were only added rather recently (JDK-8223051), so most likely this just hasn't been implemented yet. [~roland] might want to comment on this.
16-02-2024

We can also see if its possible to reassociate for non-counted loops as well
16-02-2024