Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit ca283c3

Browse files
Wang HuangAi Jiaming
authored andcommitted
8265907: JVM crashes when matching VectorMaskCmp Node
Co-authored-by: Wang Huang <whuang@openjdk.org> Co-authored-by: Ai Jiaming <aijiaming1@huawei.com> Reviewed-by: njian, jbhateja, sviswanathan, dlong, adinn
1 parent c3c9189 commit ca283c3

File tree

5 files changed

+75
-5
lines changed

5 files changed

+75
-5
lines changed

src/hotspot/cpu/aarch64/aarch64.ad

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,11 @@ const bool Matcher::match_rule_supported_vector(int opcode, int vlen, BasicType
24132413
return false;
24142414
}
24152415
break;
2416+
case Op_VectorMaskCmp:
2417+
if (vlen < 2 || bit_size < 64) {
2418+
return false;
2419+
}
2420+
break;
24162421
default:
24172422
break;
24182423
}

src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,11 @@ void C2_MacroAssembler::load_vector_mask(XMMRegister dst, XMMRegister src, int v
14981498

14991499
void C2_MacroAssembler::load_iota_indices(XMMRegister dst, Register scratch, int vlen_in_bytes) {
15001500
ExternalAddress addr(StubRoutines::x86::vector_iota_indices());
1501-
if (vlen_in_bytes <= 16) {
1501+
if (vlen_in_bytes == 4) {
1502+
movdl(dst, addr);
1503+
} else if (vlen_in_bytes == 8) {
1504+
movq(dst, addr);
1505+
} else if (vlen_in_bytes == 16) {
15021506
movdqu(dst, addr, scratch);
15031507
} else if (vlen_in_bytes == 32) {
15041508
vmovdqu(dst, addr, scratch);
@@ -1507,6 +1511,7 @@ void C2_MacroAssembler::load_iota_indices(XMMRegister dst, Register scratch, int
15071511
evmovdqub(dst, k0, addr, false /*merge*/, Assembler::AVX_512bit, scratch);
15081512
}
15091513
}
1514+
15101515
// Reductions for vectors of bytes, shorts, ints, longs, floats, and doubles.
15111516

15121517
void C2_MacroAssembler::reduce_operation_128(BasicType typ, int opcode, XMMRegister dst, XMMRegister src) {

src/hotspot/cpu/x86/x86.ad

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1835,6 +1835,11 @@ const bool Matcher::match_rule_supported_vector(int opcode, int vlen, BasicType
18351835
return false;
18361836
}
18371837
break;
1838+
case Op_VectorMaskCmp:
1839+
if (vlen < 2 || size_in_bits < 32) {
1840+
return false;
1841+
}
1842+
break;
18381843
}
18391844
return true; // Per default match rules are supported.
18401845
}
@@ -6918,7 +6923,7 @@ instruct evcmpFD(vec dst, vec src1, vec src2, immI8 cond, rRegP scratch, kReg kt
69186923
instruct vcmp(legVec dst, legVec src1, legVec src2, immI8 cond, rRegP scratch) %{
69196924
predicate((UseAVX <= 2 || !VM_Version::supports_avx512vl()) &&
69206925
!is_unsigned_booltest_pred(n->in(2)->get_int()) &&
6921-
vector_length_in_bytes(n->in(1)->in(1)) >= 8 && // src1
6926+
vector_length_in_bytes(n->in(1)->in(1)) >= 4 && // src1
69226927
vector_length_in_bytes(n->in(1)->in(1)) <= 32 && // src1
69236928
is_integral_type(vector_element_basic_type(n->in(1)->in(1)))); // src1
69246929
match(Set dst (VectorMaskCmp (Binary src1 src2) cond));

src/hotspot/share/opto/vectorIntrinsics.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,6 @@ bool LibraryCallKit::inline_vector_shuffle_iota() {
411411
int num_elem = vlen->get_con();
412412
BasicType elem_bt = T_BYTE;
413413

414-
if (num_elem < 4)
415-
return false;
416-
417414
if (!arch_supports_vector(VectorNode::replicate_opcode(elem_bt), num_elem, elem_bt, VecMaskNotUsed)) {
418415
return false;
419416
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2021, Huawei Technologies Co. Ltd. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package compiler.vectorapi;
25+
26+
import jdk.incubator.vector.IntVector;
27+
import jdk.incubator.vector.VectorSpecies;
28+
import jdk.incubator.vector.VectorShuffle;
29+
30+
/*
31+
* @test
32+
* @bug 8265907
33+
* @modules jdk.incubator.vector
34+
* @run main/othervm compiler.vectorapi.TestVectorShuffleIota
35+
*/
36+
37+
public class TestVectorShuffleIota {
38+
static final VectorSpecies<Integer> SPECIESi = IntVector.SPECIES_128;
39+
40+
static final int INVOC_COUNT = 50000;
41+
42+
static int[] ai = {87, 65, 78, 71};
43+
44+
static void testShuffleI() {
45+
IntVector iv = (IntVector) VectorShuffle.iota(SPECIESi, 0, 2, false).toVector();
46+
iv.intoArray(ai, 0);
47+
}
48+
49+
public static void main(String[] args) {
50+
for (int i = 0; i < INVOC_COUNT; i++) {
51+
testShuffleI();
52+
}
53+
for (int i = 0; i < ai.length; i++) {
54+
System.out.print(ai[i] + ", ");
55+
}
56+
System.out.println();
57+
}
58+
}

0 commit comments

Comments
 (0)