Skip to content

8296389: C2: PhaseCFG::convert_NeverBranch_to_Goto must handle both orders of successors #11481

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

Conversation

eme64
Copy link
Contributor

@eme64 eme64 commented Dec 2, 2022

The code in PhaseCFG::convert_NeverBranch_to_Goto looks like it is ready to have idx == 1, but it is not.

We would read succ from _succs[1].

Block *succ = b->_succs[idx];

Then overwrite _succs[0] with succ, and shorten the array.

b->_succs.map(0,succ); // Map only successor
b->_num_succs = 1;

And finally attempt to read dead from _succs[0], where the dead block used to be, but was just overwritten.

Block* dead = b->_succs[1 - idx];

Solution
Read dead before overwriting it. I also made it more robust by going via the projections, and not assuming that the projections and successors are ordered equally (though that is probably guaranteed by the matching traversal).

Refactoring: added class id for NeverBranch
I also added the class id for NeverBranch, and replaced all Op_NeverBranch checks with is_NeverBranch().

Why did we never hit this bug before?
Normal case: during matching, "succ" projection is added as output of NeverBranch before the "dead" projection leading to Halt. Thus, the outputs of NeverBranch are normally [[ "succ", "dead" ]], hence idx == 0.
Details: During DFS, usually we go from Halt to NeverBranch. Then via Region/Loop, take backedge, and find the "succ" edge. We already have its inputs (NeverBranch), thus we can now post-visit the live edge, and attach it to the NeverBranch first. Later, once we have processed the whole infinite loop, we post-visit out of NeverBranch to the "dead" projection edge, which we attach second.

Rare case: "dead" projection is first attached to NeverBranch, and "succ" projection is added second. We have [[ "dead", "succ" ]], hence idx == 1.
We have a peeled infinite loop. The NeverBranch of the peeled iteration is first visited via the "dead" projection from HaltNode. Since the peeled iteration has no backedge, we do not visit the "succ" projection yet, but instead attach "dead" projection to HaltNode already once we are done visiting everything above. Later, we come from the peeled loop's NeverBranch exit, to the "succ" projection of the peeled iteration's NeverBranch, and attach the "succ" projection.

image


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-8296389: C2: PhaseCFG::convert_NeverBranch_to_Goto must handle both orders of successors

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11481

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 2, 2022

👋 Welcome back epeter! 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 Dec 2, 2022

@eme64 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 Dec 2, 2022
@eme64 eme64 marked this pull request as ready for review December 2, 2022 13:08
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 2, 2022
@mlbridge
Copy link

mlbridge bot commented Dec 2, 2022

Webrevs

@eme64 eme64 requested a review from TobiHartmann December 9, 2022 07:06
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.

Much better, thanks for making these changes. Looks good.

@openjdk
Copy link

openjdk bot commented Dec 9, 2022

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

8296389: C2: PhaseCFG::convert_NeverBranch_to_Goto must handle both orders of successors

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 25 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 Dec 9, 2022
Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
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.

Nice analysis and tests! The fix looks good to me, too.

@eme64
Copy link
Contributor Author

eme64 commented Dec 12, 2022

Thanks @chhagedorn @TobiHartmann for the reviews!
/integrate

@openjdk
Copy link

openjdk bot commented Dec 12, 2022

Going to push as commit fabda24.
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 Dec 12, 2022
@openjdk openjdk bot closed this Dec 12, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 12, 2022
@openjdk
Copy link

openjdk bot commented Dec 12, 2022

@eme64 Pushed as commit fabda24.

💡 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