Skip to content
Permalink
Browse files

8249602: C2: assert(cnt == _outcnt) failed: no insertions allowed

Use DUIterator instead of DUIterator_Fast due to legit insertions.

Reviewed-by: kvn, thartmann
  • Loading branch information
chhagedorn committed Jul 28, 2020
1 parent aff80ee commit 31368cd1f06c486ec48fd64b14d8d660f9434e05
@@ -1480,14 +1480,14 @@ void PhaseIdealLoop::insert_pre_post_loops(IdealLoopTree *loop, Node_List &old_n
Node_Stack clones(main_head->back_control()->outcnt());
// Step B3: Make the fall-in values to the main-loop come from the
// fall-out values of the pre-loop.
for (DUIterator_Fast i2max, i2 = main_head->fast_outs(i2max); i2 < i2max; i2++) {
Node* main_phi = main_head->fast_out(i2);
for (DUIterator i2 = main_head->outs(); main_head->has_out(i2); i2++) {
Node* main_phi = main_head->out(i2);
if (main_phi->is_Phi() && main_phi->in(0) == main_head && main_phi->outcnt() > 0) {
Node *pre_phi = old_new[main_phi->_idx];
Node *fallpre = clone_up_backedge_goo(pre_head->back_control(),
main_head->skip_strip_mined()->in(LoopNode::EntryControl),
pre_phi->in(LoopNode::LoopBackControl),
visited, clones);
Node* pre_phi = old_new[main_phi->_idx];
Node* fallpre = clone_up_backedge_goo(pre_head->back_control(),
main_head->skip_strip_mined()->in(LoopNode::EntryControl),
pre_phi->in(LoopNode::LoopBackControl),
visited, clones);
_igvn.hash_delete(main_phi);
main_phi->set_req(LoopNode::EntryControl, fallpre);
}
@@ -1765,11 +1765,11 @@ Node *PhaseIdealLoop::insert_post_loop(IdealLoopTree *loop, Node_List &old_new,
Node_Stack clones(main_head->back_control()->outcnt());
// Step A3: Make the fall-in values to the post-loop come from the
// fall-out values of the main-loop.
for (DUIterator_Fast imax, i = main_head->fast_outs(imax); i < imax; i++) {
Node* main_phi = main_head->fast_out(i);
for (DUIterator i = main_head->outs(); main_head->has_out(i); i++) {
Node* main_phi = main_head->out(i);
if (main_phi->is_Phi() && main_phi->in(0) == main_head && main_phi->outcnt() > 0) {
Node *cur_phi = old_new[main_phi->_idx];
Node *fallnew = clone_up_backedge_goo(main_head->back_control(),
Node* cur_phi = old_new[main_phi->_idx];
Node* fallnew = clone_up_backedge_goo(main_head->back_control(),
post_head->init_control(),
main_phi->in(LoopNode::LoopBackControl),
visited, clones);
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2020, 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
* 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 8249602
* @summary Tests the rewiring and cloning of fall-in values from the main loop (and pre loop) to the post (and main loop)
* which resulted in a DUIterator_Fast assertion failure due to an insertion in the outputs of the loop header node.
*
* @run main compiler.loopopts.TestPreMainPostFallInEdges
*/

package compiler.loopopts;

public class TestPreMainPostFallInEdges {

public static int test() {
int iArr[] = new int[400];
float fArr[] = new float[400];
int x = 0;
byte y = 124;
short z = 0;

int i = 1;
do {
int j = 1;
do {
z *= 11;

// These 4 array stores live in the back control block and cannot float. They are cloned and their control input set to the preheader control
// block of the post loop. If their input edges also have their placement in the back control block (get_ctrl == back control) then they are
// cloned as well. The following code hits the assertion failure when we clone a node with a control edge to the loop header block of the main.
// loop. The DUIterator_Fast does not allow insertions. The fix is to replace it by a normal DUIterator which allows insertions.
iArr[j] = 3;
// load of iArr[j + 1] is also cloned but has a control edge to the main loop header block hitting the assertion failure.
iArr[j + 1] += 4;
fArr[j] = 5;
fArr[j + 1] += fArr[j + 5]; // same for load of fArr[j + 1] and load of fArr[j + 5]

int k = 1;
do {
iArr[j] *= 324;
x = 34;
y *= 54;
} while (k < 1);
} while (++j < 6);
} while (++i < 289);
return checkSum(iArr) + checkSum(fArr);
}

public static int checkSum(int[] a) {
int sum = 0;
for (int j = 0; j < a.length; j++) {
sum += a[j] % (j + 1);
}
return sum;
}

public static int checkSum(float[] a) {
int sum = 0;
for (int j = 0; j < a.length; j++) {
sum += a[j] % (j + 1);
}
return sum;
}

public static void main(String[] strArr) {
for (int i = 0; i < 10000; i++) {
test();
}
}
}

0 comments on commit 31368cd

Please sign in to comment.