Navigation Menu

Skip to content

Commit

Permalink
8251994: VM crashed running TestComplexAddrExpr.java test with -XX:Us…
Browse files Browse the repository at this point in the history
…eAVX=X

Reviewed-by: shade, redestad
  • Loading branch information
Vladimir Kozlov committed Oct 26, 2020
1 parent b498433 commit a7fa1b7
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/hotspot/share/opto/superword.cpp
Expand Up @@ -91,6 +91,8 @@ SuperWord::SuperWord(PhaseIdealLoop* phase) :
#endif
}

static const bool _do_vector_loop_experimental = false; // Experimental vectorization which uses data from loop unrolling.

//------------------------------transform_loop---------------------------
void SuperWord::transform_loop(IdealLoopTree* lpt, bool do_optimization) {
assert(UseSuperWord, "should be");
Expand Down Expand Up @@ -470,7 +472,7 @@ void SuperWord::SLP_extract() {
CountedLoopNode *cl = lpt()->_head->as_CountedLoop();
bool post_loop_allowed = (PostLoopMultiversioning && Matcher::has_predicated_vectors() && cl->is_post_loop());
if (cl->is_main_loop()) {
if (_do_vector_loop) {
if (_do_vector_loop_experimental) {
if (mark_generations() != -1) {
hoist_loads_in_graph(); // this only rebuild the graph; all basic structs need rebuild explicitly

Expand Down Expand Up @@ -508,11 +510,13 @@ void SuperWord::SLP_extract() {

extend_packlist();

if (_do_vector_loop) {
if (_do_vector_loop_experimental) {
if (_packset.length() == 0) {
#ifndef PRODUCT
if (TraceSuperWord) {
tty->print_cr("\nSuperWord::_do_vector_loop DFA could not build packset, now trying to build anyway");
}
#endif
pack_parallel();
}
}
Expand Down Expand Up @@ -1723,7 +1727,14 @@ void SuperWord::construct_my_pack_map() {
Node_List* p = _packset.at(i);
for (uint j = 0; j < p->size(); j++) {
Node* s = p->at(j);
assert(my_pack(s) == NULL, "only in one pack");
#ifdef ASSERT
if (my_pack(s) != NULL) {
s->dump(1);
tty->print_cr("packs[%d]:", i);
print_pack(p);
assert(false, "only in one pack");
}
#endif
set_my_pack(s, p);
}
}
Expand All @@ -1738,7 +1749,7 @@ void SuperWord::filter_packs() {
bool impl = implemented(pk);
if (!impl) {
#ifndef PRODUCT
if (TraceSuperWord && Verbose) {
if ((TraceSuperWord && Verbose) || _vector_loop_debug) {
tty->print_cr("Unimplemented");
pk->at(0)->dump();
}
Expand All @@ -1762,7 +1773,7 @@ void SuperWord::filter_packs() {
bool prof = profitable(pk);
if (!prof) {
#ifndef PRODUCT
if (TraceSuperWord && Verbose) {
if ((TraceSuperWord && Verbose) || _vector_loop_debug) {
tty->print_cr("Unprofitable");
pk->at(0)->dump();
}
Expand Down Expand Up @@ -3052,12 +3063,13 @@ bool SuperWord::construct_bb() {

int ii_current = -1;
unsigned int load_idx = (unsigned int)-1;
_ii_order.clear();
// Build iterations order if needed
bool build_ii_order = _do_vector_loop_experimental && _ii_order.is_empty();
// Create real map of block indices for nodes
for (int j = 0; j < _block.length(); j++) {
Node* n = _block.at(j);
set_bb_idx(n, j);
if (_do_vector_loop && n->is_Load()) {
if (build_ii_order && n->is_Load()) {
if (ii_current == -1) {
ii_current = _clone_map.gen(n->_idx);
_ii_order.push(ii_current);
Expand Down Expand Up @@ -4700,6 +4712,15 @@ bool SuperWord::pack_parallel() {

_packset.clear();

if (_ii_order.is_empty()) {
#ifndef PRODUCT
if (_vector_loop_debug) {
tty->print_cr("SuperWord::pack_parallel: EMPTY");
}
#endif
return false;
}

for (int ii = 0; ii < _iteration_first.length(); ii++) {
Node* nd = _iteration_first.at(ii);
if (in_bb(nd) && (nd->is_Load() || nd->is_Store() || nd->is_Add() || nd->is_Mul())) {
Expand Down
130 changes: 130 additions & 0 deletions test/hotspot/jtreg/compiler/vectorization/TestForEachRem.java
@@ -0,0 +1,130 @@
/*
* 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 8251994
* @summary Test vectorization of Streams$RangeIntSpliterator::forEachRemaining
* @requires vm.compiler2.enabled & vm.compMode != "Xint"
*
* @run main compiler.vectorization.TestForEachRem test1
* @run main compiler.vectorization.TestForEachRem test2
* @run main compiler.vectorization.TestForEachRem test3
* @run main compiler.vectorization.TestForEachRem test4
*/

package compiler.vectorization;

import java.util.stream.IntStream;

public class TestForEachRem {
static final int RANGE = 512;
static final int ITER = 100;

static void test1(int[] data) {
IntStream.range(0, RANGE).parallel().forEach(j -> {
data[j] = j + 1;
});
}

static void test2(int[] data) {
IntStream.range(0, RANGE - 1).forEach(j -> {
data[j] = data[j] + data[j + 1];
});
}

static void test3(int[] data, int A, int B) {
IntStream.range(0, RANGE - 1).forEach(j -> {
data[j] = A * data[j] + B * data[j + 1];
});
}

static void test4(int[] data) {
IntStream.range(0, RANGE - 1).forEach(j -> {
data[j + 1] = data[j];
});
}

static void verify(String name, int[] data, int[] gold) {
for (int i = 0; i < RANGE; i++) {
if (data[i] != gold[i]) {
throw new RuntimeException(" Invalid " + name + " result: data[" + i + "]: " + data[i] + " != " + gold[i]);
}
}
}

public static void main(String[] args) {
int[] data = new int[RANGE];
int[] gold = new int[RANGE];

if (args.length == 0) {
throw new RuntimeException(" Missing test name: test1, test2, test3, test4");
}

if (args[0].equals("test1")) {
System.out.println(" Run test1 ...");
test1(gold);
for (int i = 0; i < ITER; i++) {
test1(data);
}
verify("test1", data, gold);
System.out.println(" Finished test1.");
}

if (args[0].equals("test2")) {
System.out.println(" Run test2 ...");
test1(gold);
test2(gold);
for (int i = 0; i < ITER; i++) {
test1(data); // reset
test2(data);
}
verify("test2", data, gold);
System.out.println(" Finished test2.");
}

if (args[0].equals("test3")) {
System.out.println(" Run test3 ...");
test1(gold);
test3(gold, 2, 3);
for (int i = 0; i < ITER; i++) {
test1(data); // reset
test3(data, 2, 3);
}
verify("test3", data, gold);
System.out.println(" Finished test3.");
}

if (args[0].equals("test4")) {
System.out.println(" Run test4 ...");
test1(gold); // reset
test4(gold);
for (int i = 0; i < ITER; i++) {
test1(data); // reset
test4(data);
}
verify("test4", data, gold);
System.out.println(" Finished test4.");
}
}
}
76 changes: 76 additions & 0 deletions test/hotspot/jtreg/compiler/vectorization/TestOptionVectorize.java
@@ -0,0 +1,76 @@
/*
* 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 8251994
* @summary Test forced vectorization
* @requires vm.compiler2.enabled & vm.compMode != "Xint"
*
* @run main/othervm -XX:CompileCommand=option,*::test,Vectorize compiler.vectorization.TestOptionVectorize
*/

package compiler.vectorization;

import java.util.stream.IntStream;

public class TestOptionVectorize {
static final int RANGE = 512;
static final int ITER = 100;

static void init(double[] data) {
IntStream.range(0, RANGE).parallel().forEach(j -> {
data[j] = j + 1;
});
}

static void test(double[] data, double A, double B) {
for (int i = RANGE - 1; i > 0; i--) {
for (int j = 0; j <= i - 1; j++) {
data[j] = A * data[j + 1] + B * data[j];
}
}
}

static void verify(double[] data, double[] gold) {
for (int i = 0; i < RANGE; i++) {
if (data[i] != gold[i]) {
throw new RuntimeException(" Invalid result: data[" + i + "]: " + data[i] + " != " + gold[i]);
}
}
}

public static void main(String[] args) {
double[] data = new double[RANGE];
double[] gold = new double[RANGE];
System.out.println(" Run test ...");
init(gold); // reset
test(gold, 1.0, 2.0);
for (int i = 0; i < ITER; i++) {
init(data); // reset
test(data, 1.0, 2.0);
}
verify(data, gold);
System.out.println(" Finished test.");
}
}

1 comment on commit a7fa1b7

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on a7fa1b7 Oct 26, 2020

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.