Skip to content

Commit a6faf5d

Browse files
author
Xiaohong Gong
committed
8290485: [vector] REVERSE_BYTES for byte type should not emit any instructions
Reviewed-by: thartmann, kvn
1 parent 0ca5cb1 commit a6faf5d

File tree

4 files changed

+123
-2
lines changed

4 files changed

+123
-2
lines changed

src/hotspot/share/opto/vectornode.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -1852,15 +1852,20 @@ Node* NegVNode::Ideal(PhaseGVN* phase, bool can_reshape) {
18521852
}
18531853

18541854
Node* ReverseBytesVNode::Identity(PhaseGVN* phase) {
1855+
// "(ReverseBytesV X) => X" if the element type is T_BYTE.
1856+
if (vect_type()->element_basic_type() == T_BYTE) {
1857+
return in(1);
1858+
}
1859+
18551860
if (is_predicated_using_blend()) {
18561861
return this;
18571862
}
1858-
// ReverseBytesV (ReverseBytesV X , MASK) , MASK => X
1863+
// (ReverseBytesV (ReverseBytesV X MASK) MASK) => X
18591864
if (in(1)->Opcode() == Op_ReverseBytesV) {
18601865
if (is_predicated_vector() && in(1)->is_predicated_vector() && in(2) == in(1)->in(2)) {
18611866
return in(1)->in(1);
18621867
} else {
1863-
// ReverseBytesV (ReverseBytesV X) => X
1868+
// ReverseBytesV (ReverseBytesV X) => X
18641869
return in(1)->in(1);
18651870
}
18661871
}
@@ -1972,6 +1977,14 @@ Node* XorVNode::Ideal(PhaseGVN* phase, bool can_reshape) {
19721977
return NULL;
19731978
}
19741979

1980+
Node* VectorBlendNode::Identity(PhaseGVN* phase) {
1981+
// (VectorBlend X X MASK) => X
1982+
if (in(1) == in(2)) {
1983+
return in(1);
1984+
}
1985+
return this;
1986+
}
1987+
19751988
#ifndef PRODUCT
19761989
void VectorBoxAllocateNode::dump_spec(outputStream *st) const {
19771990
CallStaticJavaNode::dump_spec(st);

src/hotspot/share/opto/vectornode.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,7 @@ class VectorBlendNode : public VectorNode {
14491449
}
14501450

14511451
virtual int Opcode() const;
1452+
virtual Node* Identity(PhaseGVN* phase);
14521453
Node* vec1() const { return in(1); }
14531454
Node* vec2() const { return in(2); }
14541455
Node* vec_mask() const { return in(3); }

test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java

+2
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ public class IRNode {
208208
public static final String VECTOR_UCAST_S2X = START + "VectorUCastS2X" + MID + END;
209209
public static final String VECTOR_UCAST_I2X = START + "VectorUCastI2X" + MID + END;
210210
public static final String VECTOR_REINTERPRET = START + "VectorReinterpret" + MID + END;
211+
public static final String VECTOR_BLEND = START + "VectorBlend" + MID + END;
212+
public static final String REVERSE_BYTES_V = START + "ReverseBytesV" + MID + END;
211213

212214
public static final String Min_V = START + "MinV" + MID + END;
213215
public static final String Max_V = START + "MaxV" + MID + END;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2022, Arm Limited. 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 compiler.lib.ir_framework.*;
27+
28+
import java.util.Random;
29+
30+
import jdk.incubator.vector.ByteVector;
31+
import jdk.incubator.vector.VectorMask;
32+
import jdk.incubator.vector.VectorOperators;
33+
import jdk.incubator.vector.VectorSpecies;
34+
35+
import jdk.test.lib.Asserts;
36+
import jdk.test.lib.Utils;
37+
38+
/**
39+
* @test
40+
* @bug 8290485
41+
* @key randomness
42+
* @library /test/lib /
43+
* @summary [vectorapi] REVERSE_BYTES for byte type should not emit any instructions
44+
* @requires vm.compiler2.enabled
45+
* @requires (os.simpleArch == "x64" & vm.cpu.features ~= ".*avx2.*") | os.arch == "aarch64"
46+
* @modules jdk.incubator.vector
47+
*
48+
* @run driver compiler.vectorapi.VectorReverseBytesTest
49+
*/
50+
51+
public class VectorReverseBytesTest {
52+
private static final VectorSpecies<Byte> B_SPECIES = ByteVector.SPECIES_MAX;
53+
54+
private static int LENGTH = 1024;
55+
private static final Random RD = Utils.getRandomInstance();
56+
57+
private static byte[] input;
58+
private static byte[] output;
59+
private static boolean[] m;
60+
61+
static {
62+
input = new byte[LENGTH];
63+
output = new byte[LENGTH];
64+
m = new boolean[LENGTH];
65+
66+
for (int i = 0; i < LENGTH; i++) {
67+
input[i] = (byte) RD.nextInt(25);
68+
m[i] = RD.nextBoolean();
69+
}
70+
}
71+
72+
@Test
73+
@IR(failOn = IRNode.REVERSE_BYTES_V)
74+
public static void testReverseBytesV() {
75+
for (int i = 0; i < LENGTH; i += B_SPECIES.length()) {
76+
ByteVector v = ByteVector.fromArray(B_SPECIES, input, i);
77+
v.lanewise(VectorOperators.REVERSE_BYTES).intoArray(output, i);
78+
}
79+
80+
// Verify results
81+
for (int i = 0; i < LENGTH; i++) {
82+
Asserts.assertEquals(input[i], output[i]);
83+
}
84+
}
85+
86+
@Test
87+
@IR(failOn = IRNode.REVERSE_BYTES_V)
88+
@IR(failOn = IRNode.VECTOR_BLEND)
89+
public static void testReverseBytesVMasked() {
90+
VectorMask<Byte> mask = VectorMask.fromArray(B_SPECIES, m, 0);
91+
for (int i = 0; i < LENGTH; i += B_SPECIES.length()) {
92+
ByteVector v = ByteVector.fromArray(B_SPECIES, input, i);
93+
v.lanewise(VectorOperators.REVERSE_BYTES, mask).intoArray(output, i);
94+
}
95+
96+
// Verify results
97+
for (int i = 0; i < LENGTH; i++) {
98+
Asserts.assertEquals(input[i], output[i]);
99+
}
100+
}
101+
102+
public static void main(String[] args) {
103+
TestFramework.runWithFlags("--add-modules=jdk.incubator.vector");
104+
}
105+
}

0 commit comments

Comments
 (0)