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

8283187: C2: loop candidate for superword not always unrolled fully if superword fails #7822

Closed
wants to merge 7 commits into from

Conversation

rwestrel
Copy link
Contributor

@rwestrel rwestrel commented Mar 15, 2022

IdealLoopTree::policy_unroll_slp_analysis() restricts unrolling of
loops that are found to be candidate for superword but if superword
then fails, unrolling doesn't always resume. SuperWord::output() has
logic for that in one of the failure paths but some other paths are
not covered (for instance in the case of the test case). I propose
that superword explictly returns whether it succeeded or not and that
in case of failure, for a main loop, unrolling be attempted again.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8283187: C2: loop candidate for superword not always unrolled fully if superword fails

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/7822/head:pull/7822
$ git checkout pull/7822

Update a local copy of the PR:
$ git checkout pull/7822
$ git pull https://git.openjdk.java.net/jdk pull/7822/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 7822

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/7822.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 15, 2022

👋 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
Copy link

openjdk bot commented Mar 15, 2022

@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 Mar 15, 2022
@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 15, 2022
@mlbridge
Copy link

mlbridge bot commented Mar 15, 2022

Webrevs

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.

Good catch! The fix looks good to me.

@openjdk
Copy link

openjdk bot commented Mar 22, 2022

@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:

8283187: C2: loop candidate for superword not always unrolled fully if superword fails

Reviewed-by: thartmann, chagedorn

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 24 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 Mar 22, 2022
…ling.java

Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
@rwestrel
Copy link
Contributor Author

Good catch! The fix looks good to me.

thanks for the review! I applied your suggestions.

Copy link
Member

@chhagedorn chhagedorn left a comment

Choose a reason for hiding this comment

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

That looks good!

if (!cl->is_valid_counted_loop(T_INT)) return false; // skip malformed counted loop

bool post_loop_allowed = (PostLoopMultiversioning && Matcher::has_predicated_vectors() && cl->is_post_loop());
if (post_loop_allowed) {
if (cl->is_reduction_loop()) return; // no predication mapping
if (cl->is_reduction_loop()) return false; // no predication mapping
Node *limit = cl->limit();
if (limit->is_Con()) return; // non constant limits only
if (limit->is_Con()) return false; // non constant limits only
// Now check the limit for expressions we do not handle
if (limit->is_Add()) {
Node *in2 = limit->in(2);
if (in2->is_Con()) {
int val = in2->get_int();
// should not try to program these cases
if (val < 0) return;
if (val < 0) return false;
}
}
}

// skip any loop that has not been assigned max unroll by analysis
if (do_optimization) {
if (SuperWordLoopUnrollAnalysis && cl->slp_max_unroll() == 0) return;
if (SuperWordLoopUnrollAnalysis && cl->slp_max_unroll() == 0) return false;
Copy link
Member

Choose a reason for hiding this comment

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

While at it, you could also add braces for the one liner ifs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be done in the new commit

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.

I executed some testing and compiler/c2/irTests/TestSuperwordFailsUnrolling.java fails on Windows only with:

java.lang.Error: failed to install whitebox classes
	at compiler.lib.ir_framework.TestFramework.installWhiteBox(TestFramework.java:529)
	at compiler.lib.ir_framework.TestFramework.start(TestFramework.java:318)
	at compiler.lib.ir_framework.TestFramework.run(TestFramework.java:210)
	at compiler.lib.ir_framework.TestFramework.run(TestFramework.java:199)
	at compiler.c2.irTests.TestSuperwordFailsUnrolling.main(TestSuperwordFailsUnrolling.java:48)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:577)
	at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:127)
	at java.base/java.lang.Thread.run(Thread.java:828)
Caused by: java.nio.file.FileSystemException: sun\\hotspot\\WhiteBox.class: The process cannot access the file because it is being used by another process
	at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92)
	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
	at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:275)
	at java.base/sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:110)
	at java.base/java.nio.file.Files.deleteIfExists(Files.java:1191)
	at java.base/java.nio.file.Files.copy(Files.java:3149)
	at jdk.test.lib.helpers.ClassFileInstaller.writeToDisk(ClassFileInstaller.java:296)
	at jdk.test.lib.helpers.ClassFileInstaller.writeClassToDisk(ClassFileInstaller.java:255)
	at jdk.test.lib.helpers.ClassFileInstaller.writeClassToDisk(ClassFileInstaller.java:237)
	at jdk.test.lib.helpers.ClassFileInstaller.writeClassToDisk(ClassFileInstaller.java:234)
	at jdk.test.lib.helpers.ClassFileInstaller.main(ClassFileInstaller.java:97)
	at compiler.lib.ir_framework.TestFramework.installWhiteBox(TestFramework.java:527)
	... 8 more

Weird but reproducible.

@TobiHartmann
Copy link
Member

Let me try to reproduce with -DSkipWhiteBoxInstall=true.

@TobiHartmann
Copy link
Member

This fixes the issue:

- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI compiler.c2.irTests.TestSuperwordFailsUnrolling
+ * @run main/othervm -Xbootclasspath/a:. -DSkipWhiteBoxInstall=true -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI compiler.c2.irTests.TestSuperwordFailsUnrolling

@chhagedorn Maybe the IR verification framework could detect this automatically?

@chhagedorn
Copy link
Member

This fixes the issue:

- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI compiler.c2.irTests.TestSuperwordFailsUnrolling
+ * @run main/othervm -Xbootclasspath/a:. -DSkipWhiteBoxInstall=true -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI compiler.c2.irTests.TestSuperwordFailsUnrolling

@chhagedorn Maybe the IR verification framework could detect this automatically?

Yes, it would be good to extend the framework to handle this. I added this -DSkipWhiteBoxInstall flag at some point to prevent the problem above but was more of a quick fix. I will follow up with an RFE to make this better without the need to use -DSkipWhiteBoxInstall.

@rwestrel
Copy link
Contributor Author

This fixes the issue:

- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI compiler.c2.irTests.TestSuperwordFailsUnrolling
+ * @run main/othervm -Xbootclasspath/a:. -DSkipWhiteBoxInstall=true -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI compiler.c2.irTests.TestSuperwordFailsUnrolling

New commit has this change

@rwestrel
Copy link
Contributor Author

That looks good!

Thanks for the review @chhagedorn

@openjdk
Copy link

openjdk bot commented Mar 23, 2022

⚠️ @rwestrel This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

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.

Copy link
Member

@chhagedorn chhagedorn 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, thanks for the updates!

if (!cl->is_valid_counted_loop(T_INT)) return false; // skip malformed counted loop

bool post_loop_allowed = (PostLoopMultiversioning && Matcher::has_predicated_vectors() && cl->is_post_loop());
if (post_loop_allowed) {
if (cl->is_reduction_loop()) return; // no predication mapping
if (cl->is_reduction_loop()) return false; // no predication mapping
Node *limit = cl->limit();
if (limit->is_Con()) return; // non constant limits only
if (limit->is_Con()) return false; // non constant limits only
// Now check the limit for expressions we do not handle
if (limit->is_Add()) {
Node *in2 = limit->in(2);
if (in2->is_Con()) {
int val = in2->get_int();
// should not try to program these cases
if (val < 0) return;
if (val < 0) return false;
}
}
}

// skip any loop that has not been assigned max unroll by analysis
if (do_optimization) {
if (SuperWordLoopUnrollAnalysis && cl->slp_max_unroll() == 0) return;
if (SuperWordLoopUnrollAnalysis && cl->slp_max_unroll() == 0) return false;
Copy link
Member

Choose a reason for hiding this comment

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

While at it, you could also add braces for the one liner ifs.

@rwestrel
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Mar 24, 2022

Going to push as commit 14c20bc.
Since your change was applied there have been 25 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 Mar 24, 2022
@openjdk openjdk bot closed this Mar 24, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Mar 24, 2022
@openjdk
Copy link

openjdk bot commented Mar 24, 2022

@rwestrel Pushed as commit 14c20bc.

💡 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
3 participants