Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8336759: C2: int counted loop with long limit not recognized as counted loop #22449

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

tabjy
Copy link
Member

@tabjy tabjy commented Nov 29, 2024

This patch implements JDK-8336759 that recognizes int counted loops with long limits.

Currently, patterns like for ( int i =...; i < long_limit; ...) where int i is implicitly promoted to long (i.e., (long) i < long_limit) is not recognized as (int) counted loop. This patch speculatively and optimistically converts long limits to ints and deoptimize if the limit is outside int range, allowing more optimization opportunities.

In other words, it transforms

for (int i = 0; (long) i < long_limit; i++) {...}

to

if (int_min <= long_limit && long_limit <= int_max ) {
    for (int i = 0;  i < (int) long_limit; i++) {...}
} else {
    trap: loop_limit_check
}

This could benefit calls to APIs like long MemorySegment#byteSize() when iterating over a long limit.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 2 Reviewers)

Issue

  • JDK-8336759: C2: int counted loop with long limit not recognized as counted loop (Enhancement - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22449

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 29, 2024

👋 Welcome back kxu! 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

openjdk bot commented Nov 29, 2024

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

@openjdk
Copy link

openjdk bot commented Nov 29, 2024

@tabjy 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.

@tabjy tabjy changed the title 8336759: int counted loop with long limit not recognized as counted loop 8336759: C2: int counted loop with long limit not recognized as counted loop Nov 29, 2024
@tabjy
Copy link
Member Author

tabjy commented Nov 29, 2024

/reviewers 2 reviewer

C2 changes

@openjdk
Copy link

openjdk bot commented Nov 29, 2024

@tabjy
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 2 Reviewers).

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

Successfully merging this pull request may close these issues.

3 participants