Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8272574: C2: assert(false) failed: Bad graph detected in build_loop_late
Co-authored-by: Hui Shi <hshi@openjdk.org>
Co-authored-by: Christian Hagedorn <chagedorn@openjdk.org>
Reviewed-by: thartmann, chagedorn, kvn
  • Loading branch information
3 people authored and DamonFool committed Sep 14, 2021
1 parent e7ab372 commit 16c3ad1
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 5 deletions.
21 changes: 18 additions & 3 deletions src/hotspot/share/opto/loopPredicate.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -621,7 +621,7 @@ class Invariance : public StackObj {
// Returns true if the predicate of iff is in "scale*iv + offset u< load_range(ptr)" format
// Note: this function is particularly designed for loop predication. We require load_range
// and offset to be loop invariant computed on the fly by "invar"
bool IdealLoopTree::is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar) const {
bool IdealLoopTree::is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar DEBUG_ONLY(COMMA ProjNode *predicate_proj)) const {
if (!is_loop_exit(iff)) {
return false;
}
Expand Down Expand Up @@ -662,6 +662,21 @@ bool IdealLoopTree::is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invari
if (offset && !invar.is_invariant(offset)) { // offset must be invariant
return false;
}
#ifdef ASSERT
if (offset && phase->has_ctrl(offset)) {
Node* offset_ctrl = phase->get_ctrl(offset);
if (phase->get_loop(predicate_proj) == phase->get_loop(offset_ctrl) &&
phase->is_dominator(predicate_proj, offset_ctrl)) {
// If the control of offset is loop predication promoted by previous pass,
// then it will lead to cyclic dependency.
// Previously promoted loop predication is in the same loop of predication
// point.
// This situation can occur when pinning nodes too conservatively - can we do better?
assert(false, "cyclic dependency prevents range check elimination, idx: offset %d, offset_ctrl %d, predicate_proj %d",
offset->_idx, offset_ctrl->_idx, predicate_proj->_idx);
}
}
#endif
return true;
}

Expand Down Expand Up @@ -1141,7 +1156,7 @@ bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree *loop, ProjNode*
loop->dump_head();
}
#endif
} else if (cl != NULL && loop->is_range_check_if(iff, this, invar)) {
} else if (cl != NULL && loop->is_range_check_if(iff, this, invar DEBUG_ONLY(COMMA predicate_proj))) {
// Range check for counted loops
const Node* cmp = bol->in(1)->as_Cmp();
Node* idx = cmp->in(1);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/opto/loopnode.hpp
Expand Up @@ -737,7 +737,7 @@ class IdealLoopTree : public ResourceObj {
bool policy_range_check( PhaseIdealLoop *phase ) const;

// Return TRUE if "iff" is a range check.
bool is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar) const;
bool is_range_check_if(IfNode *iff, PhaseIdealLoop *phase, Invariance& invar DEBUG_ONLY(COMMA ProjNode *predicate_proj)) const;

// Estimate the number of nodes required when cloning a loop (body).
uint est_loop_clone_sz(uint factor) const;
Expand Down
9 changes: 8 additions & 1 deletion src/hotspot/share/opto/memnode.cpp
Expand Up @@ -1626,7 +1626,14 @@ Node *LoadNode::split_through_phi(PhaseGVN *phase) {
the_clone = x; // Remember for possible deletion.
// Alter data node to use pre-phi inputs
if (this->in(0) == region) {
x->set_req(0, in);
if (mem->is_Phi() && (mem->in(0) == region) && mem->in(i)->in(0) != NULL &&
MemNode::all_controls_dominate(address, region)) {
// Enable other optimizations such as loop predication which does not work
// if we directly pin the node to node `in`
x->set_req(0, mem->in(i)->in(0)); // Use same control as memory
} else {
x->set_req(0, in);
}
} else {
x->set_req(0, NULL);
}
Expand Down
69 changes: 69 additions & 0 deletions test/hotspot/jtreg/compiler/loopopts/TestLoopPredicateDep.java
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/**
* @test
* @bug 8272574
* @summary Crashes in PhaseIdealLoop::build_loop_late_post_work
* @requires vm.compiler2.enabled
*
* @run main TestLoopPredicateDep
*
*/

public class TestLoopPredicateDep {
public static void getPermutations(byte[] inputArray, byte[][] outputArray) {
int[] indexes = new int[]{0, 2};

for (int a = 0; a < a + 16; a++) {
int oneIdx = indexes[0]++;
for (int b = a + 1; b < inputArray.length; b++) {
int twoIdx = indexes[1]++;
outputArray[twoIdx][0] = inputArray[a];
outputArray[twoIdx][1] = inputArray[b];
}
}
}

public static void main(String[] args) {
final byte[] inputArray = new byte[]{0, 1};
final byte[][] outputArray = new byte[3][2];

for (int i = 0; i < 10; ++i) {
Thread t = new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 1000000; i++) {
getPermutations(inputArray, outputArray);
}
}
});
t.setDaemon(true);
t.start();
try {
Thread.sleep(100);
} catch (Exception e) {
}
}
}

}

3 comments on commit 16c3ad1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@TheRealMDoerr
Copy link
Contributor

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 16c3ad1 Oct 13, 2021

Choose a reason for hiding this comment

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

@TheRealMDoerr @TheRealMDoerr the backport was successfully created on the branch TheRealMDoerr-backport-16c3ad1f in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

this pull request contains a backport of commit 16c3ad1f from the openjdk/jdk repository.

The commit being backported was authored by casparcwang on 14 Sep 2021 and was reviewed by Tobias Hartmann, Christian Hagedorn and Vladimir Kozlov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev TheRealMDoerr-backport-16c3ad1f:TheRealMDoerr-backport-16c3ad1f
$ git checkout TheRealMDoerr-backport-16c3ad1f
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev TheRealMDoerr-backport-16c3ad1f

Please sign in to comment.