Skip to content

Commit

Permalink
8286125: C2: "bad AD file" with PopulateIndex on x86_64
Browse files Browse the repository at this point in the history
Reviewed-by: kvn, thartmann
  • Loading branch information
Pengfei Li committed May 10, 2022
1 parent 9e320d9 commit 1ca5404
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/hotspot/share/opto/superword.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2849,16 +2849,24 @@ Node* SuperWord::vector_opd(Node_List* p, int opd_idx) {
uint vlen = p->size();
Node* opd = p0->in(opd_idx);
CountedLoopNode *cl = lpt()->_head->as_CountedLoop();
bool have_same_inputs = same_inputs(p, opd_idx);

if (cl->is_rce_post_loop()) {
// override vlen with the main loops vector length
assert(p->size() == 1, "Packs in post loop should have only one node");
vlen = cl->slp_max_unroll();
}

// Insert index population operation
if (opd == iv()) {
// Insert index population operation to create a vector of increasing
// indices starting from the iv value. In some special unrolled loops
// (see JDK-8286125), we need scalar replications of the iv value if
// all inputs are the same iv, so we do a same inputs check here. But
// in post loops, "have_same_inputs" is always true because all packs
// are singleton. That's why a pack size check is also required.
if (opd == iv() && (!have_same_inputs || p->size() == 1)) {
BasicType p0_bt = velt_basic_type(p0);
BasicType iv_bt = is_subword_type(p0_bt) ? p0_bt : T_INT;
assert(VectorNode::is_populate_index_supported(iv_bt), "Should support");
const TypeVect* vt = TypeVect::make(iv_bt, vlen);
Node* vn = new PopulateIndexNode(iv(), _igvn.intcon(1), vt);
#ifdef ASSERT
Expand All @@ -2872,7 +2880,7 @@ Node* SuperWord::vector_opd(Node_List* p, int opd_idx) {
return vn;
}

if (same_inputs(p, opd_idx)) {
if (have_same_inputs) {
if (opd->is_Vector() || opd->is_LoadVector()) {
assert(((opd_idx != 2) || !VectorNode::is_shift(p0)), "shift's count can't be vector");
if (opd_idx == 2 && VectorNode::is_shift(p0)) {
Expand Down
55 changes: 55 additions & 0 deletions test/hotspot/jtreg/compiler/vectorization/TestReplicateLoopIV.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2022, Arm 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 8286125
* @summary C2: "bad AD file" with PopulateIndex on x86_64
*
* @run main/othervm -Xbatch -XX:MaxVectorSize=16 compiler.vectorization.TestReplicateLoopIV
*/

package compiler.vectorization;

public class TestReplicateLoopIV {

public static long[] arr = new long[400];

public static void bar() {
for (int i = 304; i > 15; i -= 3) {
int c = 16;
do {
for (int t = 1; t < 1; t++) {}
arr[c + 1] >>= i;
} while (--c > 0);
}
}

public static void main(String[] args) {
int iter = 100000;
while (iter-- > 0) {
bar();
}
}
}

1 comment on commit 1ca5404

@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.