Skip to content

Commit

Permalink
8290432: C2 compilation fails with assert(node->_last_del == _last) f…
Browse files Browse the repository at this point in the history
…ailed: must have deleted the edge just produced

Reviewed-by: kvn, thartmann, chagedorn
  • Loading branch information
y1yang0 committed Dec 7, 2022
1 parent ce89673 commit acf96c6
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/hotspot/share/opto/loopnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3657,11 +3657,13 @@ bool PhaseIdealLoop::is_deleteable_safept(Node* sfpt) {
void PhaseIdealLoop::replace_parallel_iv(IdealLoopTree *loop) {
assert(loop->_head->is_CountedLoop(), "");
CountedLoopNode *cl = loop->_head->as_CountedLoop();
if (!cl->is_valid_counted_loop(T_INT))
if (!cl->is_valid_counted_loop(T_INT)) {
return; // skip malformed counted loop
}
Node *incr = cl->incr();
if (incr == NULL)
if (incr == NULL) {
return; // Dead loop?
}
Node *init = cl->init_trip();
Node *phi = cl->phi();
int stride_con = cl->stride_con();
Expand All @@ -3670,25 +3672,33 @@ void PhaseIdealLoop::replace_parallel_iv(IdealLoopTree *loop) {
for (DUIterator i = cl->outs(); cl->has_out(i); i++) {
Node *out = cl->out(i);
// Look for other phis (secondary IVs). Skip dead ones
if (!out->is_Phi() || out == phi || !has_node(out))
if (!out->is_Phi() || out == phi || !has_node(out)) {
continue;
}

PhiNode* phi2 = out->as_Phi();
Node *incr2 = phi2->in( LoopNode::LoopBackControl );
Node* incr2 = phi2->in(LoopNode::LoopBackControl);
// Look for induction variables of the form: X += constant
if (phi2->region() != loop->_head ||
incr2->req() != 3 ||
incr2->in(1)->uncast() != phi2 ||
incr2 == incr ||
incr2->Opcode() != Op_AddI ||
!incr2->in(2)->is_Con())
!incr2->in(2)->is_Con()) {
continue;
}

if (incr2->in(1)->is_ConstraintCast() &&
!(incr2->in(1)->in(0)->is_IfProj() && incr2->in(1)->in(0)->in(0)->is_RangeCheck())) {
// Skip AddI->CastII->Phi case if CastII is not controlled by local RangeCheck
continue;
}
// Check for parallel induction variable (parallel to trip counter)
// via an affine function. In particular, count-down loops with
// count-up array indices are common. We only RCE references off
// the trip-counter, so we need to convert all these to trip-counter
// expressions.
Node *init2 = phi2->in( LoopNode::EntryControl );
Node* init2 = phi2->in(LoopNode::EntryControl);
int stride_con2 = incr2->in(2)->get_int();

// The ratio of the two strides cannot be represented as an int
Expand Down
95 changes: 95 additions & 0 deletions test/hotspot/jtreg/compiler/c2/TestUnexpectedParallelIV.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2022, Alibaba Group Holding Limited. 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 8290432
* @summary Unexpected parallel induction variable pattern was recongized
*
* @run main/othervm -XX:-TieredCompilation -Xcomp
* -XX:CompileCommand=compileonly,compiler.c2.TestUnexpectedParallelIV::test
* -XX:CompileCommand=compileonly,compiler.c2.TestUnexpectedParallelIV::test2
* -XX:CompileCommand=quiet
* -XX:CompileCommand=dontinline,compiler.c2.TestUnexpectedParallelIV::* compiler.c2.TestUnexpectedParallelIV
*/

package compiler.c2;

public class TestUnexpectedParallelIV {

static boolean bFld;

static int dontInline() {
return 0;
}

static int test2(int i1) {
int i2, i3 = 0, i4, i5 = 0, i6;
for (i2 = 0; 4 > i2; ++i2) {
for (i4 = 1; i4 < 5; ++i4) {
i3 -= --i1;
i6 = 1;
while (++i6 < 2) {
dontInline();
if (bFld) {
i1 = 5;
}
}
if (bFld) {
break;
}
}
}
return i3;
}

static long test(int val, boolean b) {
long ret = 0;
long dArr[] = new long[100];
for (int i = 15; 293 > i; ++i) {
ret = val;
int j = 1;
while (++j < 6) {
int k = (val--);
for (long l = i; 1 > l; ) {
if (k != 0) {
ret += dontInline();
}
}
if (b) {
break;
}
}
}
return ret;
}

public static void main(String[] args) {
for (int i = 0; i < 1000; i++) {
test(0, false);
}

test2(5);
}
}

1 comment on commit acf96c6

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.