Skip to content

8281322: C2: always construct strip mined loop initially (even if strip mining is disabled) #7364

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

Conversation

rwestrel
Copy link
Contributor

@rwestrel rwestrel commented Feb 7, 2022

Some of the long range check transformations take advantage of the
safepoint captured by loop strip mining to extract jvm state (in order
to add back empty predicates to the inner loop of a loop nest). As a
consequence, irTests/TestLongRangeChecks.java fails with strip mining
off and users might experience performance anomalies where changing
GCs affect purely computational code.

The strip mined loop nest creation is a 2 step process:

1- when a CountedLoop is created, an OuterStripMinedLoop is also added
but it's not fully constructed

2- at macro expansion time, the OuterStripMinedLoop is turned into an
actual loop by adding Phis and a proper exit condition

I propose always doing 1- whether loop strip mining is enabled or
not. This causes the safepoint to always be captured. Loop strip ming
is not expected to get in the way of loop transformations so this
change in itself should be performance neutral. Then at 2-, if loop
strip mining is not enabled, the OuterStripMinedLoop can be removed
and the safepoint moved back into the loop in case
LoopStripMiningIter=1 or simply removed too.


Progress

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

Issue

  • JDK-8281322: C2: always construct strip mined loop initially (even if strip mining is disabled)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 7364

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

Using diff file

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

@bridgekeeper
Copy link

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

mlbridge bot commented Feb 7, 2022

Webrevs

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 reasonable. I'll submit some testing.

igvn->replace_input_of(inner_cl, LoopBackControl, in(LoopBackControl));
// make the outer loop go away
igvn->replace_input_of(this, LoopBackControl, igvn->C->top());
igvn->C->print_method(PHASE_DEBUG, 2);
Copy link
Member

Choose a reason for hiding this comment

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

Probably a left-over and can be removed.

Node* outer_test = outer_le->in(1);

// make counted loop exit test always fail to
igvn->replace_input_of(cle, 1, outer_test);
Copy link
Member

Choose a reason for hiding this comment

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

Might be clearer to directly use igvn->intcon(0) instead of outer_test.

@openjdk
Copy link

openjdk bot commented Feb 8, 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:

8281322: C2: always construct strip mined loop initially (even if strip mining is disabled)

Reviewed-by: chagedorn, 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 3 new commits pushed to the master branch:

  • 5f3d403: 8272735: Add missing SubL node transformations
  • 01570ca: 8283017: GHA: Workflows break with update release versions
  • c0e3d10: 8283008: KRegister documentation out of date

Please see this link for an up-to-date comparison between the source branch of this pull request and 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 Feb 8, 2022
@TobiHartmann
Copy link
Member

For the record: Christian's testing found issues (he reported them to Roland already).

I think it would be good to change the bug title to something more descriptive.

@rwestrel
Copy link
Contributor Author

For the record: Christian's testing found issues (he reported them to Roland already).

8282045 (When loop strip mining fails, safepoints are removed from loop anyway) is an underlying issue that Christian's testing caught.

@openjdk
Copy link

openjdk bot commented Mar 7, 2022

@rwestrel this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout JDK-8281322
git fetch https://git.openjdk.java.net/jdk master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added merge-conflict Pull request has merge conflict with target branch and removed ready Pull request is ready to be integrated labels Mar 7, 2022
@rwestrel
Copy link
Contributor Author

rwestrel commented Mar 7, 2022

I pushed a number of new commits that address 3 issues (with LoopStripMiningIter=1):
1- the previous logic would drop nodes pinned on the backedge when the loop nest is transformed back to a single loop.
2- sunk stores need to be moved back into the loop which requires the inner loop's memory graph to be updated. I reused existing logic for that (OuterStripMinedLoopNode::fix_sunk_stores())
3- long counted loop support has a similar transform from a loop nest back to a single counted loop. That transform didn't have part 2 above. I'm not sure if it can cause actually bugs as I expect the counted loop to be transformed back to a loop nest next. In any case, rather than duplicate the logic, I refactored the code so it calls the new OuterStripMinedLoopNode::transform_to_counted_loop() instead. Having it callable from both igvn and loop opts requires some care.

@rwestrel rwestrel changed the title 8281322: irTests/TestLongRangeChecks.java fails with strip mining off 8281322: C2: always construct strip mined loop initially (even if strip mining is disabled) Mar 7, 2022
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Mar 7, 2022
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Mar 7, 2022
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.

This looks reasonable to me. All tests passed.

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.

Apart from some minor code style things, the update looks good to me!

if (u->is_Store()) {
int alias_idx = igvn->C->get_alias_index(u->adr_type());
Node* first = u;
for(;;) {
Copy link
Member

Choose a reason for hiding this comment

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

Missing space after for.

first = next;
}
Node* last = u;
for(;;) {
Copy link
Member

Choose a reason for hiding this comment

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

Missing space after for.

}
#endif
if (phi == NULL) {
// If the an entire chains was sunk, the
Copy link
Member

Choose a reason for hiding this comment

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

If the an entire chains -> If an entire chain

@@ -2623,6 +2564,123 @@ BaseCountedLoopNode* BaseCountedLoopNode::make(Node* entry, Node* backedge, Basi
return new LongCountedLoopNode(entry, backedge);
}

void OuterStripMinedLoopNode::fix_sunk_stores(CountedLoopEndNode* inner_cle, LoopNode* target, PhaseIterGVN* igvn,
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to rename target to inner_cl as we are also using inner_cle already. Maybe you can also add some more comments for the intermediate steps (even though most of the code was just moved in this change).

@rwestrel
Copy link
Contributor Author

Apart from some minor code style things, the update looks good to me!

Thanks. The new commit should take care of your comments.

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.

Thanks for the updates, looks good!

@rwestrel
Copy link
Contributor Author

@TobiHartmann @chhagedorn thanks for the reviews

@rwestrel
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Mar 14, 2022

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

  • 5f3d403: 8272735: Add missing SubL node transformations
  • 01570ca: 8283017: GHA: Workflows break with update release versions
  • c0e3d10: 8283008: KRegister documentation out of date

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Mar 14, 2022

@rwestrel Pushed as commit ea9eeea.

💡 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