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

8301489: C1: ShortLoopOptimizer might lift instructions before their inputs #14492

Closed
wants to merge 10 commits into from

Conversation

danielogh
Copy link
Contributor

@danielogh danielogh commented Jun 15, 2023

ShortLoopOptimizer might lift instructions before their inputs on some graph shapes. We propose adding a check that the insertion point for an instruction that is a candidate for hoisting should not be higher up the dominator tree than any inputs to the instruction.

Testing: tier1-tier3.

Additional testing: observed that (cur_invariant && !v.is_valid()) never occurs on tier1-tier3 before the added test case.
Also verified that the depth check is equivalent to (*vp->block() == _insert->block()) || dominates(*vp, _insert) on all of tier1-tier3.

Failure case: in the attached image the arraylength instruction from B10 is lifted to B0, as the dominator of B10 is calculated as B0. This is based on the logic in ComputeLinearScanOrder::compute_dominator_impl. But the array input is in Block 3. This is later spotted in c1_LIRAssembler.cpp with Error: ShouldNotReachHere(). We can reproduce the error on other instructions too -- the reader may refer to the test case provided.

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-8301489: C1: ShortLoopOptimizer might lift instructions before their inputs (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14492

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 15, 2023

👋 Welcome back danielogh! 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 Jun 15, 2023
@openjdk
Copy link

openjdk bot commented Jun 15, 2023

@danielogh 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 Jun 15, 2023
@mlbridge
Copy link

mlbridge bot commented Jun 15, 2023

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.

Great work investigating this, Daniel!

From your comments in JBS, it seems that the underlying issue is additional exception edges in the graph that affect dominator computation. Could you elaborate a bit more on that with respect to the example that you provided in the PR description?

I'm not an expert in C1 though (paging @veresov and @rwestrel as the author of JDK-7153771).

Thanks,
Tobias

Comment on lines 378 to 380
#ifdef ASSERT
assert(insert != nullptr, "insertion point should not be null");
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#ifdef ASSERT
assert(insert != nullptr, "insertion point should not be null");
#endif
assert(insert != nullptr, "insertion point should not be null");

}

public:
bool is_valid() {return _valid; }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bool is_valid() {return _valid; }
bool is_valid() { return _valid; }

Value _insert;
bool _valid = true;

void visit(Value* vp) {
Copy link
Member

Choose a reason for hiding this comment

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

Since Value is already a pointer type, can't we use Value v here?

Copy link
Contributor Author

@danielogh danielogh Jun 20, 2023

Choose a reason for hiding this comment

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

I am not sure if this is possible without changing the ValueVisitor (ref) itself

Copy link
Member

Choose a reason for hiding this comment

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

Right, makes sense.

Copy link
Contributor

@robcasloz robcasloz 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, analysis, and regression test Daniel. Great that you could generalize the fix to cover all other LICM cases. Just a couple of comments/suggestions.

@@ -359,6 +359,28 @@ LoopInvariantCodeMotion::LoopInvariantCodeMotion(ShortLoopOptimizer *slo, Global
}
}

class CheckInsertionPoint: public ValueVisitor {
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency with other similar cases in c1_ValueMap.cpp:

Suggested change
class CheckInsertionPoint: public ValueVisitor {
class CheckInsertionPoint : public ValueVisitor {

Comment on lines 420 to 421
CheckInsertionPoint v(_insertion_point);
cur->input_values_do(&v);
Copy link
Contributor

Choose a reason for hiding this comment

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

For compilation efficiency, would it be possible to perform this computation only when cur_invariant holds? You could for example encapsulate the creation of v, call to cur->input_values_do(&v), and v.is_valid() check into an auxiliary function is_dominated_by_inputs(_insertion_point, cur) or similar and call that function below (if (cur_invariant && is_dominated_by_inputs(_insertion_point, cur)) {).

@danielogh
Copy link
Contributor Author

Great work investigating this, Daniel!

From your comments in JBS, it seems that the underlying issue is additional exception edges in the graph that affect dominator computation. Could you elaborate a bit more on that with respect to the example that you provided in the PR description?

I'm not an expert in C1 though (paging @veresov and @rwestrel as the author of JDK-7153771).

Thanks, Tobias

Thank you very much for review!

My understanding is, this might have been introduced in JDK-7153771, where we have extra edges to the exception handler of all successors during dominator calculation -- Additional edge to xhandler of all our successors. The client RangeCheckElimination optimization needed this additional information, but the short loop optimization was not updated accordingly. In this specific case, I observed using print debugging and -XX:TraceLinearScanLevel=4, that the dominator of B10 is being calculated as common_dominator(B7, B1). But B1 has dominator B0 because of the extra edge from B14 to B1 (the exception handler of B3). The short loop optimization lifts loop invariant instructions to the dominator of the loop header, which in this case becomes B0.

@danielogh danielogh changed the title 8301489: ShortLoopOptimizer might lift instructions before their inputs 8301489: C1: ShortLoopOptimizer might lift instructions before their inputs Jun 20, 2023
Copy link
Contributor

@robcasloz robcasloz 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 addressing the suggestions and for the additional explanation, looks good!

@openjdk
Copy link

openjdk bot commented Jun 21, 2023

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

8301489: C1: ShortLoopOptimizer might lift instructions before their inputs

Reviewed-by: thartmann, rcastanedalo

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

  • 990e3a7: 8308899: Introduce Classfile context and improve Classfile options
  • 79c056e: 8006421: GraphicsConfiguration of a frame is changed when the frame is moved to another screen
  • 45b581b: 8309583: AArch64: Optimize firstTrue() when amount of elements < 8
  • 87e6fab: 8310873: Re-enable locked_create_entry symbol check in runtime/NMT/CheckForProperDetailStackTrace.java for RISC-V
  • 39fa4e6: 8310489: New test runtime/ClassInitErrors/TestStackOverflowDuringInit.java failed
  • 46add3f: 8310909: java.io.InvalidObjectException has redundant @since tag
  • 8f5b677: 8310908: Non-standard @since tag in com.sun.java.accessibility.util.package-info
  • a197ee7: 8310838: Correct range notations in MethodTypeDesc specification
  • 7c6a28f: 8310922: java/lang/Class/forName/ForNameNames.java fails after being added by JDK-8310242
  • 7db2f08: 8310242: Clarify the name parameter to Class::forName
  • ... and 138 more: https://git.openjdk.org/jdk/compare/6b942893868fa1a64977288bdbdb1bbff8bd9d9c...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@TobiHartmann, @robcasloz) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 21, 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.

@danielogh
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jun 27, 2023
@openjdk
Copy link

openjdk bot commented Jun 27, 2023

@danielogh
Your change (at version 074d1ed) is now ready to be sponsored by a Committer.

@danielogh
Copy link
Contributor Author

Thanks Roberto and Tobias for review. Thanks Roberto for additional help with PR.

@TobiHartmann
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Jun 27, 2023

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

  • 990e3a7: 8308899: Introduce Classfile context and improve Classfile options
  • 79c056e: 8006421: GraphicsConfiguration of a frame is changed when the frame is moved to another screen
  • 45b581b: 8309583: AArch64: Optimize firstTrue() when amount of elements < 8
  • 87e6fab: 8310873: Re-enable locked_create_entry symbol check in runtime/NMT/CheckForProperDetailStackTrace.java for RISC-V
  • 39fa4e6: 8310489: New test runtime/ClassInitErrors/TestStackOverflowDuringInit.java failed
  • 46add3f: 8310909: java.io.InvalidObjectException has redundant @since tag
  • 8f5b677: 8310908: Non-standard @since tag in com.sun.java.accessibility.util.package-info
  • a197ee7: 8310838: Correct range notations in MethodTypeDesc specification
  • 7c6a28f: 8310922: java/lang/Class/forName/ForNameNames.java fails after being added by JDK-8310242
  • 7db2f08: 8310242: Clarify the name parameter to Class::forName
  • ... and 138 more: https://git.openjdk.org/jdk/compare/6b942893868fa1a64977288bdbdb1bbff8bd9d9c...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jun 27, 2023

@TobiHartmann @danielogh Pushed as commit 73d7aa1.

💡 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