-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8281429: PhiNode::Value() is too conservative for tripcount of CountedLoop #7823
Conversation
👋 Welcome back roland! A progress list of the required criteria for merging this PR into |
Webrevs
|
There was a problem hiding this 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 otherwise.
inner_head = inner_loop->_head->as_Loop(); | ||
inner_head->verify_strip_mined(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove the verification code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hit a failure in that code for an inner loop that no longer has the shape of a counted loop. Let me double check if I can still reproduce it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the update I just pushed, I reverted that change, added a test that causes the failure that this was supposed to fix. The new fix is the new cast in in PhaseIdealLoop::do_unroll(). Without it, c2 can't remove the back branch of a main loop and the graph contains a counted loop that doesn't have the right shape anymore (the exit test doesn't depend on the iv phi after transformation but doesn't constant fold).
@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:
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
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 |
src/hotspot/share/opto/cfgnode.cpp
Outdated
julong ulo = static_cast<julong>(lo->hi_as_long()); | ||
julong diff = (uhi - ulo - 1) / (-stride_t->lo_as_long()) * (-stride_t->lo_as_long()); | ||
julong ufirst = hi->lo_as_long() - diff; | ||
first = reinterpret_cast<jlong &>(ufirst); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also use a static_cast
here and further down instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking at this.
I'm not sure. I modeled this code on java_add/java_substract etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that just for a numeric conversion, one could use static_cast
as reinterpret_cast
operates on pointers or references. But I'm not entirely sure what the convention should be. I guess both should work fine.
Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I executed testing and the "no iterations?" assert triggers. I'll follow up with details on how to reproduce.
Thanks for reviewing this. |
The following test triggers
Please add it as regression test. |
Done in the updated change. |
src/hotspot/share/opto/cfgnode.cpp
Outdated
julong ulo = static_cast<julong>(lo->hi_as_long()); | ||
julong diff = (uhi - ulo - 1) / (-stride_t->lo_as_long()) * (-stride_t->lo_as_long()); | ||
julong ufirst = hi->lo_as_long() - diff; | ||
first = reinterpret_cast<jlong &>(ufirst); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that just for a numeric conversion, one could use static_cast
as reinterpret_cast
operates on pointers or references. But I'm not entirely sure what the convention should be. I guess both should work fine.
* @bug 8282592 | ||
* @summary C2: assert(false) failed: graph should be schedulable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the changes to this file intended? They seem to be unrelated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are unrelated but I noticed, while working on this change, that that test has the wrong bug/summary. So yes unrelated but also intended (not sure a separate change is required?)
src/hotspot/share/opto/loopnode.cpp
Outdated
@@ -844,9 +844,18 @@ bool PhaseIdealLoop::create_loop_nest(IdealLoopTree* loop, Node_List &old_new) { | |||
} | |||
|
|||
// May not have gone thru igvn yet so don't use _igvn.type(phi) (PhaseIdealLoop::is_counted_loop() sets the iv phi's type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment seems to be outdated as we are not querying the type of the phi anymore. Can you update it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I updated it.
There was a problem hiding this 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. All tests passed.
Thanks @TobiHartmann |
Still looks good to me. Another review would be good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be correctness tests for MAX_INT,MIN_INT,MAX_LONG,MIN_LONG boundaries, positive and negative strides and abs(stride) != 1
. All combinations.
src/hotspot/share/opto/cfgnode.cpp
Outdated
@@ -1117,9 +1117,35 @@ const Type* PhiNode::Value(PhaseGVN* phase) const { | |||
if (bt != BoolTest::ne) { | |||
if (stride_t->hi_as_long() < 0) { // Down-counter loop | |||
swap(lo, hi); | |||
return TypeInteger::make(MIN2(lo->lo_as_long(), hi->lo_as_long()), hi->hi_as_long(), 3, l->bt())->filter_speculative(_type); | |||
jlong first = lo->lo_as_long(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first
is misleading/confusing name here. I assume first
is init
but it is limit
in this case. I would prefer to have corresponding name to low limit
of range.
src/hotspot/share/opto/cfgnode.cpp
Outdated
@@ -1117,9 +1117,35 @@ const Type* PhiNode::Value(PhaseGVN* phase) const { | |||
if (bt != BoolTest::ne) { | |||
if (stride_t->hi_as_long() < 0) { // Down-counter loop | |||
swap(lo, hi); | |||
return TypeInteger::make(MIN2(lo->lo_as_long(), hi->lo_as_long()), hi->hi_as_long(), 3, l->bt())->filter_speculative(_type); | |||
jlong first = lo->lo_as_long(); | |||
if (first < max_signed_integer(l->bt())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand this condition is to avoid overflow in next statement. And I thought it should take stride
into account:
if (first < (max_signed_integer(l->bt()) + stride_t->hi_as_long() + 1)) {
But since we don't know (in general) what final iv
value would be with abs(stride) != 1
using value 1
is conservative and correct here.
In short, this condition and following statement needs comment to explain why 1
is used.
src/hotspot/share/opto/cfgnode.cpp
Outdated
jlong first = lo->lo_as_long(); | ||
if (first < max_signed_integer(l->bt())) { | ||
first += 1; // lo is after decrement | ||
// When bounds are constant and ABS(stride) greater than 1, exact bounds for the phi can be computed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is confusing - it sounds like we can calculate it only when stride
is not 1. I think you mean:
// Exact bounds for the phi can be computed with ABS(stride) greater than 1 when bounds are constant.
src/hotspot/share/opto/cfgnode.cpp
Outdated
if (first < max_signed_integer(l->bt())) { | ||
first += 1; // lo is after decrement | ||
// When bounds are constant and ABS(stride) greater than 1, exact bounds for the phi can be computed | ||
if (lo->is_con() && hi->is_con() && hi->lo_as_long() > lo->hi_as_long() && stride_t->lo_as_long() != -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stride
is constant. May be used the value instead of calling stride_t->lo_as_long()
3 times in this code.
Hi Vladimir. Thanks for reviewing this.
That's reasonable but what kind of tests? Executing a simple counted loop that iterates from MIN_INT to MAX_INT is unlikely to lead to an incorrect result even if the iv type is wrong. |
I am concern about unsigned arithmetic to calculate new limit for long indexing case. The test could simple fill up an array and you then check that values in it are correct (and no out of bounds references). You can choose big |
The problem is this code: It makes it impossible to construct a counted loop with limit Integer.MAX_VALUE with a big stride. |
I am fine with testing range [MIN_VALUE + stride, MAX_VALUE - stride] to exercise unsigned arithmetic. Whatever maximum loopopts allows. |
@vnkozlov the new commits should address your comments. Let me know if the new tests cover what you asked for. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Thank you.
@vnkozlov thanks for the review |
/integrate |
Going to push as commit fa1ca98.
Your commit was automatically rebased without conflicts. |
The type for the iv phi of a counted loop is computed from the types
of the phi on loop entry and the type of the limit from the exit
test. Because the exit test is applied to the iv after increment, the
type of the iv phi is at least one less than the limit (for a positive
stride, one more for a negative stride).
Also, for a stride whose absolute value is not 1 and constant init and
limit values, it's possible to compute accurately the iv phi type.
This change caused a few failures and I had to make a few adjustments
to loop opts code as well.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/7823/head:pull/7823
$ git checkout pull/7823
Update a local copy of the PR:
$ git checkout pull/7823
$ git pull https://git.openjdk.java.net/jdk pull/7823/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 7823
View PR using the GUI difftool:
$ git pr show -t 7823
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/7823.diff