Skip to content

8311932: Suboptimal compiled code of nested loop over memory segment #16650

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 7 commits into from

Conversation

rwestrel
Copy link
Contributor

@rwestrel rwestrel commented Nov 14, 2023

To enable the elimination of long range checks, the loop that contains
the range checks is transformed into a loop nest and the range checks
are changed to operate on int values computed before the loop is
entered. This causes extra overhead out of loop and once, the range
checks are eliminated, can only pay off if the loop is executed for
long enough. This change disable the transformation if the trip count
computed from profile data is too low. This came up with a
MemorySegment API micro benchmarks and improves performance
significantly.


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-8311932: Suboptimal compiled code of nested loop over memory segment (Bug - P2)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16650

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 14, 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 Nov 14, 2023
@openjdk
Copy link

openjdk bot commented Nov 14, 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 Nov 14, 2023
@mlbridge
Copy link

mlbridge bot commented Nov 14, 2023

Webrevs

@TobiHartmann
Copy link
Member

TestLongRangeChecks.java fails with -ea -esa -XX:CompileThreshold=100 -XX:+UnlockExperimentalVMOptions -server -XX:-TieredCompilation:

1) Method "public static void compiler.c2.irTests.TestLongRangeChecks.testStridePosScalePosInIntLoopShortLoop1(int,int,long,long)" - [Failed IR rules: 2]:
   * @IR rule 1: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfPlatformAnd={}, applyIfCPUFeatureOr={}, counts={"_#COUNTED_LOOP#_", "1"}, applyIfPlatform={}, applyIfPlatformOr={}, failOn={}, applyIfOr={}, applyIfCPUFeatureAnd={}, applyIf={}, applyIfCPUFeature={}, applyIfAnd={}, applyIfNot={})"
     > Phase "PrintIdeal":
       - counts: Graph contains wrong number of nodes:
         * Constraint 1: "(\\d+(\\s){2}(CountedLoop\\b.*)+(\\s){2}===.*)"
           - Failed comparison: [found] 0 = 1 [given]
           - No nodes matched!
   * @IR rule 2: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfPlatformAnd={}, applyIfCPUFeatureOr={}, counts={}, applyIfPlatform={}, applyIfPlatformOr={}, failOn={"_#LOOP#_"}, applyIfOr={}, applyIfCPUFeatureAnd={}, applyIf={}, applyIfCPUFeature={}, applyIfAnd={}, applyIfNot={})"
     > Phase "PrintIdeal":
       - failOn: Graph contains forbidden nodes:
         * Constraint 1: "(\\d+(\\s){2}(Loop.*)+(\\s){2}===.*)"
           - Matched forbidden node:
             * 173  Loop  === 173 167 170  [[ 173 420 174 ]] inner 

2) Method "public static void compiler.c2.irTests.TestLongRangeChecks.testStridePosScalePosShortLoop(long,long,long,long)" - [Failed IR rules: 2]:
   * @IR rule 1: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfPlatformAnd={}, applyIfCPUFeatureOr={}, counts={"_#LONG_COUNTED_LOOP#_", "1"}, applyIfPlatform={}, applyIfPlatformOr={}, failOn={}, applyIfOr={}, applyIfCPUFeatureAnd={}, applyIf={}, applyIfCPUFeature={}, applyIfAnd={}, applyIfNot={})"
     > Phase "PrintIdeal":
       - counts: Graph contains wrong number of nodes:
         * Constraint 1: "(\\d+(\\s){2}(LongCountedLoop\\b.*)+(\\s){2}===.*)"
           - Failed comparison: [found] 0 = 1 [given]
           - No nodes matched!
   * @IR rule 2: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfPlatformAnd={}, applyIfCPUFeatureOr={}, counts={}, applyIfPlatform={}, applyIfPlatformOr={}, failOn={"_#COUNTED_LOOP#_", "_#LOOP#_"}, applyIfOr={}, applyIfCPUFeatureAnd={}, applyIf={}, applyIfCPUFeature={}, applyIfAnd={}, applyIfNot={})"
     > Phase "PrintIdeal":
       - failOn: Graph contains forbidden nodes:
         * Constraint 2: "(\\d+(\\s){2}(Loop.*)+(\\s){2}===.*)"
           - Matched forbidden node:
             * 170  Loop  === 170 165 167  [[ 170 403 171 ]] inner 

@rwestrel
Copy link
Contributor Author

TestLongRangeChecks.java fails with -ea -esa -XX:CompileThreshold=100 -XX:+UnlockExperimentalVMOptions -server -XX:-TieredCompilation:

Thanks for running testing. Should be fixed now.

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. I've re-submitted testing and report back once it passed.

@openjdk
Copy link

openjdk bot commented Nov 15, 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:

8311932: Suboptimal compiled code of nested loop over memory segment

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 96 new commits pushed to the master branch:

  • 9faead1: 8319927: Log that IEEE rounding mode was corrupted by loading a library
  • f33c874: 8319764: C2 compilation asserts during incremental inlining because Phi input is out of bounds
  • 6868b37: 8318826: C2: "Bad graph detected in build_loop_late" with incremental inlining
  • 1d96886: 8319531: FileServerHandler::discardRequestBody could be improved
  • 73e19f6: 8319825: jdk.net/jdk.net.ExtendedSocketOptions::IP_DONTFRAGMENT is missing @SInCE 19
  • faeea07: 8319747: galoisCounterMode_AESCrypt stack walking broken
  • b4c2d1c: 8319542: Fix boundaries of region to be tested with os::is_readable_range
  • c36ec2c: 8316653: Large NMethodSizeLimit triggers assert during C1 code buffer allocation
  • 2db9ea9: 8317723: C2: CountedLoopEndNodes and Zero Trip Guards are wrongly treated as Runtime Predicate
  • eaa4417: 8319301: Static analysis warnings after JDK-8318016
  • ... and 86 more: https://git.openjdk.org/jdk/compare/7c7f8ea30da7fe552bcd4f2b593fa9aad27dcdb4...master

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 Nov 15, 2023
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!

TestFramework.runWithFlags("-XX:-UseCountedLoopSafepoints");
TestFramework.runWithFlags("-XX:+UseCountedLoopSafepoints", "-XX:LoopStripMiningIter=1");
TestFramework.runWithFlags("-XX:+UseCountedLoopSafepoints", "-XX:LoopStripMiningIter=1000");
TestFramework.runWithFlags("-XX:+TieredCompilation", "-XX:-UseCountedLoopSafepoints", "-XX:LoopUnrollLimit=0");
Copy link
Member

Choose a reason for hiding this comment

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

You could add 8311932 to the @bug numbers above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in new commit.

rwestrel and others added 4 commits November 15, 2023 16:21
Co-authored-by: Christian Hagedorn <christian.hagedorn@oracle.com>
Co-authored-by: Christian Hagedorn <christian.hagedorn@oracle.com>
Co-authored-by: Christian Hagedorn <christian.hagedorn@oracle.com>
@rwestrel
Copy link
Contributor Author

Looks good!

Thanks for reviewing and for the suggestions.

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.

All tests passed.


if (range_checks.size() > 0) {
// This transformation requires peeling one iteration. Also, if it has range checks and they are eliminated by
// Loop Predication, then 2 Hoisted Check Predicates are added for one range check. Finally, transforming a long range check requires
Copy link
Member

Choose a reason for hiding this comment

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

Just noticed that the line wraps are off now - maybe you want to re-wrap these lines. But that's just a minor detail.

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, thanks for the update.

@rwestrel
Copy link
Contributor Author

@TobiHartmann @chhagedorn thanks for the reviews

@rwestrel
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Nov 17, 2023

Going to push as commit 129c470.
Since your change was applied there have been 105 commits pushed to the master branch:

  • 369bbec: 8319896: Remove monitor deflation from final audit
  • 1588dd9: 8319567: Update java/lang/invoke tests to support vm flags
  • 9727f4b: 8320199: Fix HTML 5 errors in java.math.BigInteger
  • d6aa7c8: 8314621: ClassNotFoundException due to lambda reference to elided anonymous inner class
  • 52e2878: 8319987: compilation of sealed classes leads to infinite recursion
  • b05e69f: 8320209: VectorMaskGen clobbers rflags on x86_64
  • f3ed275: 8319103: Popups that request focus are not shown on Linux with Wayland
  • 9e7a3ae: 8319630: Monitor final audit log lacks separator
  • 87be6b6: 8318757: VM_ThreadDump asserts in interleaved ObjectMonitor::deflate_monitor calls
  • 9faead1: 8319927: Log that IEEE rounding mode was corrupted by loading a library
  • ... and 95 more: https://git.openjdk.org/jdk/compare/7c7f8ea30da7fe552bcd4f2b593fa9aad27dcdb4...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 17, 2023

@rwestrel Pushed as commit 129c470.

💡 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