Skip to content

8346177: C2: optimize simple increment loops with loop-invariant strides#30473

Open
krk wants to merge 1 commit intoopenjdk:masterfrom
krk:opt-simploop-8346177
Open

8346177: C2: optimize simple increment loops with loop-invariant strides#30473
krk wants to merge 1 commit intoopenjdk:masterfrom
krk:opt-simploop-8346177

Conversation

@krk
Copy link
Copy Markdown

@krk krk commented Mar 27, 2026

The old replace_parallel_iv only optimized parallel IVs with constant increments that evenly divided the primary IV's stride. Patterns like a += field or a += param where the increment is loop-invariant but not a compile-time constant were left as accumulation loops.

This patch generalizes the optimization to accept any loop-invariant increment, adds subtraction support, and removes the exact-divisibility requirement. Instead of computing a ratio between strides, the iteration count is computed directly as (iv - init) / stride_con.

A simple benchmark for (i=0; i<100000; i++) a += inc, where inc is loop-invariant, shows the loop is fully eliminated by the patched JVM, reducing from ~7500 ns/call to ~17 ns/call.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8346177: C2: optimize simple increment loops with loop-invariant strides (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30473/head:pull/30473
$ git checkout pull/30473

Update a local copy of the PR:
$ git checkout pull/30473
$ git pull https://git.openjdk.org/jdk.git pull/30473/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30473

View PR using the GUI difftool:
$ git pr show -t 30473

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30473.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Mar 27, 2026

👋 Welcome back krk! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link
Copy Markdown

openjdk bot commented Mar 27, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Mar 27, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Mar 27, 2026

@krk The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 27, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge bot commented Mar 27, 2026

Webrevs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-compiler hotspot-compiler-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

1 participant