Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
8288112: C2: Error: ShouldNotReachHere() in Type::typerr()
Reviewed-by: dlong, kvn
  • Loading branch information
Jatin Bhateja committed Jul 14, 2022
1 parent 2bf6285 commit fd89ab8
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp
Expand Up @@ -4886,6 +4886,7 @@ void C2_MacroAssembler::vector_reverse_byte64(BasicType bt, XMMRegister dst, XMM
evprord(xtmp1, k0, src, 16, true, vec_enc);
vector_swap_nbits(8, 0x00FF00FF, dst, xtmp1, xtmp2, rtmp, vec_enc);
break;
case T_CHAR:
case T_SHORT:
// Swap upper and lower byte of each word.
vector_swap_nbits(8, 0x00FF00FF, dst, src, xtmp2, rtmp, vec_enc);
Expand Down Expand Up @@ -4917,6 +4918,7 @@ void C2_MacroAssembler::vector_reverse_byte(BasicType bt, XMMRegister dst, XMMRe
case T_INT:
vmovdqu(dst, ExternalAddress(StubRoutines::x86::vector_reverse_byte_perm_mask_int()), rtmp, vec_enc);
break;
case T_CHAR:
case T_SHORT:
vmovdqu(dst, ExternalAddress(StubRoutines::x86::vector_reverse_byte_perm_mask_short()), rtmp, vec_enc);
break;
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/share/opto/superword.cpp
Expand Up @@ -2610,6 +2610,8 @@ bool SuperWord::output() {
opc == Op_NegF || opc == Op_NegD ||
opc == Op_RoundF || opc == Op_RoundD ||
opc == Op_PopCountI || opc == Op_PopCountL ||
opc == Op_ReverseBytesI || opc == Op_ReverseBytesL ||
opc == Op_ReverseBytesUS || opc == Op_ReverseBytesS ||
opc == Op_CountLeadingZerosI || opc == Op_CountLeadingZerosL ||
opc == Op_CountTrailingZerosI || opc == Op_CountTrailingZerosL) {
assert(n->req() == 2, "only one input expected");
Expand Down Expand Up @@ -2691,7 +2693,7 @@ bool SuperWord::output() {
vlen_in_bytes = vn->as_Vector()->length_in_bytes();
} else {
if (do_reserve_copy()) {
NOT_PRODUCT(if(is_trace_loop_reverse() || TraceLoopOpts) {tty->print_cr("SWPointer::output: ShouldNotReachHere, exiting SuperWord");})
NOT_PRODUCT(if(is_trace_loop_reverse() || TraceLoopOpts) {tty->print_cr("SWPointer::output: Unhandled scalar opcode (%s), ShouldNotReachHere, exiting SuperWord", NodeClassNames[opc]);})
return false; //and reverse to backup IG
}
ShouldNotReachHere();
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/opto/vectornode.cpp
Expand Up @@ -171,6 +171,7 @@ int VectorNode::opcode(int sopc, BasicType bt) {
case Op_ReverseBytesS:
case Op_ReverseBytesI:
case Op_ReverseBytesL:
case Op_ReverseBytesUS:
return (is_integral_type(bt) ? Op_ReverseBytesV : 0);
case Op_CompressBits:
// Not implemented. Returning 0 temporarily
Expand Down
20 changes: 18 additions & 2 deletions test/hotspot/jtreg/compiler/c2/cr6340864/TestIntVect.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, 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
Expand Down Expand Up @@ -457,6 +457,10 @@ static int test() {
for (int i=0; i<ARRLEN; i++) {
errn += verify("test_srav_and: ", i, a0[i], (int)(((int)(ADD_INIT+i) & BIT_MASK)>>VALUE));
}
test_reverse_bytes(a0, a1);
for (int i=0; i<ARRLEN; i++) {
errn += verify("test_reverse_bytes: ", i, a0[i], Integer.reverseBytes(a1[i]));
}

test_pack2(p2, a1);
for (int i=0; i<ARRLEN/2; i++) {
Expand Down Expand Up @@ -922,7 +926,13 @@ static int test() {
test_srav_and(a0, a1, BIT_MASK);
}
end = System.currentTimeMillis();
System.out.println("test_srav_and: " + (end - start));

start = System.currentTimeMillis();
for (int i=0; i<ITERS; i++) {
test_reverse_bytes(a0, a1);
}
end = System.currentTimeMillis();
System.out.println("test_reverse_bytes: " + (end - start));

start = System.currentTimeMillis();
for (int i=0; i<ITERS; i++) {
Expand Down Expand Up @@ -1271,6 +1281,12 @@ static void test_unpack2_swap(int[] a0, long[] p2) {
}
}

static void test_reverse_bytes(int [] a0, int [] a1) {
for(int i = 0; i < a0.length; i++) {
a0[i] = Integer.reverseBytes(a1[i]);
}
}

static int verify(String text, int i, int elem, int val) {
if (elem != val) {
System.err.println(text + "[" + i + "] = " + elem + " != " + val);
Expand Down
19 changes: 17 additions & 2 deletions test/hotspot/jtreg/compiler/c2/cr6340864/TestLongVect.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, 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
Expand Down Expand Up @@ -432,7 +432,10 @@ static int test() {
for (int i=0; i<ARRLEN; i++) {
errn += verify("test_srav_and: ", i, a0[i], (long)(((long)(ADD_INIT+i) & BIT_MASK)>>VALUE));
}

test_reverse_bytes(a0, a1);
for (int i=0; i<ARRLEN; i++) {
errn += verify("test_reverse_bytes: ", i, a0[i], Long.reverseBytes(a1[i]));
}
}

if (errn > 0)
Expand Down Expand Up @@ -853,6 +856,13 @@ static int test() {
end = System.currentTimeMillis();
System.out.println("test_srav_and: " + (end - start));

start = System.currentTimeMillis();
for (int i=0; i<ITERS; i++) {
test_reverse_bytes(a0, a1);
}
end = System.currentTimeMillis();
System.out.println("test_reverse_bytes: " + (end - start));

return errn;
}

Expand Down Expand Up @@ -1123,6 +1133,11 @@ static void test_srav_and(long[] a0, long[] a1, long b) {
a0[i] = (long)((a1[i] & b)>>VALUE);
}
}
static void test_reverse_bytes(long[] a0, long[] a1) {
for(int i = 0; i < a0.length; i++) {
a0[i] = Long.reverseBytes(a1[i]);
}
}

static int verify(String text, int i, long elem, long val) {
if (elem != val) {
Expand Down
20 changes: 17 additions & 3 deletions test/hotspot/jtreg/compiler/c2/cr6340864/TestShortVect.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, 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
Expand Down Expand Up @@ -442,6 +442,10 @@ static int test() {
for (int i=0; i<ARRLEN; i++) {
errn += verify("test_srav_and: ", i, a0[i], (short)(((short)(ADD_INIT+i) & BIT_MASK)>>VALUE));
}
test_reverse_bytes(a0, a1);
for (int i=0; i<ARRLEN; i++) {
errn += verify("test_reverse_bytes: ", i, a0[i], Short.reverseBytes(a1[i]));
}

test_pack2(p2, a1);
for (int i=0; i<ARRLEN/2; i++) {
Expand Down Expand Up @@ -915,7 +919,13 @@ static int test() {
test_srav_and(a0, a1, BIT_MASK);
}
end = System.currentTimeMillis();
System.out.println("test_srav_and: " + (end - start));

start = System.currentTimeMillis();
for (int i=0; i<ITERS; i++) {
test_reverse_bytes(a0, a1);
}
end = System.currentTimeMillis();
System.out.println("test_reverse_bytes: " + (end - start));

start = System.currentTimeMillis();
for (int i=0; i<ITERS; i++) {
Expand Down Expand Up @@ -1237,7 +1247,11 @@ static void test_srav_and(short[] a0, short[] a1, int b) {
a0[i] = (short)((a1[i] & b)>>VALUE);
}
}

static void test_reverse_bytes(short[] a0, short[] a1) {
for(int i = 0; i < a0.length; i+=1) {
a0[i] = Short.reverseBytes(a1[i]);
}
}
static void test_pack2(int[] p2, short[] a1) {
if (p2.length*2 > a1.length) return;
for (int i = 0; i < p2.length; i+=1) {
Expand Down
140 changes: 140 additions & 0 deletions test/hotspot/jtreg/compiler/vectorization/TestReverseBytes.java
@@ -0,0 +1,140 @@
/*
* Copyright (c) 2022, 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 8288112
* @summary Auto-vectorization of ReverseBytes operations.
* @requires vm.compiler2.enabled
* @requires vm.cpu.features ~= ".*avx2.*"
* @requires os.simpleArch == "x64"
* @library /test/lib /
* @run driver compiler.vectorization.TestReverseBytes
*/

package compiler.vectorization;

import compiler.lib.ir_framework.*;
import java.util.Random;

public class TestReverseBytes {
private static final int ARRLEN = 1024;
private static final int ITERS = 11000;

private static long [] linp;
private static long [] lout;
private static int [] iinp;
private static int [] iout;
private static short [] sinp;
private static short [] sout;
private static char [] cinp;
private static char [] cout;

public static void setup() {
Random r = new Random(1024);
linp = new long[ARRLEN];
lout = new long[ARRLEN];
iinp = new int[ARRLEN];
iout = new int[ARRLEN];
sinp = new short[ARRLEN];
sout = new short[ARRLEN];
cinp = new char[ARRLEN];
cout = new char[ARRLEN];
for(int i = 0; i < ARRLEN; i++) {
linp[i] = r.nextLong();
iinp[i] = r.nextInt();
sinp[i] = (short)r.nextInt();
cinp[i] = (char)r.nextInt();
}
}

public static void main(String args[]) {
setup();
TestFramework.runWithFlags("-XX:-TieredCompilation",
"-XX:CompileThresholdScaling=0.3");
System.out.println("PASSED");
}

@Test
@IR(counts = {"ReverseBytesV" , " > 0 "})
public void test_reverse_bytes_long(long[] lout, long[] linp) {
for (int i = 0; i < lout.length; i+=1) {
lout[i] = Long.reverseBytes(linp[i]);
}
}

@Run(test = {"test_reverse_bytes_long"}, mode = RunMode.STANDALONE)
public void kernel_test_reverse_bytes_long() {
setup();
for (int i = 0; i < ITERS; i++) {
test_reverse_bytes_long(lout , linp);
}
}

@Test
@IR(counts = {"ReverseBytesV" , " > 0 "})
public void test_reverse_bytes_int(int[] iout, int[] iinp) {
for (int i = 0; i < iout.length; i+=1) {
iout[i] = Integer.reverseBytes(iinp[i]);
}
}

@Run(test = {"test_reverse_bytes_int"}, mode = RunMode.STANDALONE)
public void kernel_test_reverse_bytes_int() {
setup();
for (int i = 0; i < ITERS; i++) {
test_reverse_bytes_int(iout , iinp);
}
}

@Test
@IR(counts = {"ReverseBytesV" , " > 0 "})
public void test_reverse_bytes_short(short[] sout, short[] sinp) {
for (int i = 0; i < sout.length; i+=1) {
sout[i] = Short.reverseBytes(sinp[i]);
}
}

@Run(test = {"test_reverse_bytes_short"}, mode = RunMode.STANDALONE)
public void kernel_test_reverse_bytes_short() {
setup();
for (int i = 0; i < ITERS; i++) {
test_reverse_bytes_short(sout , sinp);
}
}

@Test
@IR(counts = {"ReverseBytesV" , " > 0 "})
public void test_reverse_bytes_char(char[] cout, char[] cinp) {
for (int i = 0; i < cout.length; i+=1) {
cout[i] = Character.reverseBytes(cinp[i]);
}
}

@Run(test = {"test_reverse_bytes_char"}, mode = RunMode.STANDALONE)
public void kernel_test_reverse_bytes_char() {
setup();
for (int i = 0; i < ITERS; i++) {
test_reverse_bytes_char(cout , cinp);
}
}
}
9 changes: 9 additions & 0 deletions test/micro/org/openjdk/bench/java/lang/Integers.java
Expand Up @@ -56,6 +56,7 @@ public class Integers {
private int[] intsTiny;
private int[] intsSmall;
private int[] intsBig;
private int[] res;

@Setup
public void setup() {
Expand All @@ -64,6 +65,7 @@ public void setup() {
intsTiny = new int[size];
intsSmall = new int[size];
intsBig = new int[size];
res = new int[size];
for (int i = 0; i < size; i++) {
strings[i] = "" + (r.nextInt(10000) - (5000));
intsTiny[i] = r.nextInt(99);
Expand Down Expand Up @@ -146,4 +148,11 @@ public void shiftLeft(Blackhole bh) {
bh.consume(intsBig[i] << intsSmall[i]);
}
}

@Benchmark
public void reverseBytes() {
for (int i = 0; i < size; i++) {
res[i] = Integer.reverseBytes(intsSmall[i]);
}
}
}
9 changes: 9 additions & 0 deletions test/micro/org/openjdk/bench/java/lang/Longs.java
Expand Up @@ -49,6 +49,7 @@ public class Longs {
@Param("500")
private int size;

private long[] res;
private String[] strings;
private long[] longArraySmall;
private long[] longArrayBig;
Expand All @@ -57,6 +58,7 @@ public class Longs {
public void setup() {
var random = ThreadLocalRandom.current();
strings = new String[size];
res = new long[size];
longArraySmall = new long[size];
longArrayBig = new long[size];
for (int i = 0; i < size; i++) {
Expand Down Expand Up @@ -141,4 +143,11 @@ public void shiftLeft(Blackhole bh) {
bh.consume(longArrayBig[i] << longArraySmall[i]);
}
}

@Benchmark
public void reverseBytes() {
for (int i = 0; i < size; i++) {
res[i] = Long.reverseBytes(longArraySmall[i]);
}
}
}

1 comment on commit fd89ab8

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