Skip to content

8300256: C2: vectorization is sometimes skipped on loops where it would succeed #12116

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

Closed
wants to merge 9 commits into from

Conversation

rwestrel
Copy link
Contributor

@rwestrel rwestrel commented Jan 20, 2023

Vectorization for a counted loop cl only proceeds if
cl->range_checks_present() returns true. The result of that method is
computed lazily and its result cached in the CountedLoopNode and never
re-computed. If PhaseIdealLoop::do_range_check() returns 0 then the
result of that computation is overwritten (no range checks
present). PhaseIdealLoop::do_range_check() counts the number of tests
present in the loop body (which is really what range_checks_present()
is about) and decrements that count for every check it eliminates
except if it's not a comparison with a LoadRange (for a reason that I
don't understand). In the case of the test (a pattern from a
ByteBuffer benchmark), not all tests are with a LoadRange. As a
result, PhaseIdealLoop::do_range_check() returns non zero even though
it eliminates all tests. As a result, vectorization is never
attempted.

There doesn't seem to be a value in caching the result of
range_checks_present() in CountedLoopNode. It's not that expensive to
compute, it's only used during loop opts and it's really hard to keep
in sync with whether the loop has still tests: several different
transformations could remove a test. What I propose instead is to keep
roughly the same approach (compute the result lazily and cache it so
it doesn't have to be re-computed) but to store it on the
IdealLoopTree instead (so it's recomputed on every loop opts pass and
there's no risk that it becomes out of sync).


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-8300256: C2: vectorization is sometimes skipped on loops where it would succeed

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12116

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 20, 2023

👋 Welcome back roland! 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 openjdk bot added the rfr Pull request is ready for review label Jan 20, 2023
@openjdk
Copy link

openjdk bot commented Jan 20, 2023

@rwestrel 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 hotspot-compiler hotspot-compiler-dev@openjdk.org label Jan 20, 2023
@mlbridge
Copy link

mlbridge bot commented Jan 20, 2023

Webrevs

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment.

@@ -3990,7 +3990,6 @@ void IdealLoopTree::dump_head() const {
if (cl->is_post_loop()) tty->print(" post");
if (cl->is_reduction_loop()) tty->print(" reduction");
if (cl->is_vectorized_loop()) tty->print(" vector");
if (cl->range_checks_present()) tty->print(" rc ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use new range_checks_present() here? The information is still useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing this.
Indeed, you're right. I updated the change.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good.

@openjdk
Copy link

openjdk bot commented Jan 25, 2023

@rwestrel This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8300256: C2: vectorization is sometimes skipped on loops where it would succeed

Reviewed-by: kvn, thartmann

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 32 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 25, 2023
Copy link
Member

@TobiHartmann TobiHartmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Maybe add a @bug 8300256 to the test.

@rwestrel
Copy link
Contributor Author

Looks good to me. Maybe add a @bug 8300256 to the test.

Thanks for the review. Yes, I will do that.

@rwestrel
Copy link
Contributor Author

FTR, the test fails on x86 (32 bits) for some reason. I changed the test so it doesn't run on x86 (32 bits).

@rwestrel
Copy link
Contributor Author

rwestrel commented Feb 1, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Feb 1, 2023

Going to push as commit 2a8ae2f.
Since your change was applied there have been 67 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Feb 1, 2023
@openjdk openjdk bot closed this Feb 1, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 1, 2023
@openjdk
Copy link

openjdk bot commented Feb 1, 2023

@rwestrel Pushed as commit 2a8ae2f.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

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 integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants