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

Commit d90e06a

Browse files
committed
8259775: [Vector API] Incorrect code-gen for VectorReinterpret operation
Reviewed-by: rbackman, neliasso, kvn
1 parent ede1bea commit d90e06a

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

src/hotspot/cpu/x86/macroAssembler_x86.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,7 +2485,6 @@ void MacroAssembler::movdqu(XMMRegister dst, Address src) {
24852485

24862486
void MacroAssembler::movdqu(XMMRegister dst, XMMRegister src) {
24872487
assert(((dst->encoding() < 16 && src->encoding() < 16) || VM_Version::supports_avx512vl()),"XMM register should be 0-15");
2488-
if (dst->encoding() == src->encoding()) return;
24892488
Assembler::movdqu(dst, src);
24902489
}
24912490

@@ -2510,7 +2509,6 @@ void MacroAssembler::vmovdqu(XMMRegister dst, Address src) {
25102509

25112510
void MacroAssembler::vmovdqu(XMMRegister dst, XMMRegister src) {
25122511
assert(((dst->encoding() < 16 && src->encoding() < 16) || VM_Version::supports_avx512vl()),"XMM register should be 0-15");
2513-
if (dst->encoding() == src->encoding()) return;
25142512
Assembler::vmovdqu(dst, src);
25152513
}
25162514

src/hotspot/cpu/x86/macroAssembler_x86.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ class MacroAssembler: public Assembler {
168168
void movflt(XMMRegister dst, AddressLiteral src);
169169
void movflt(Address dst, XMMRegister src) { movss(dst, src); }
170170

171+
// Move with zero extension
172+
void movfltz(XMMRegister dst, XMMRegister src) { movss(dst, src); }
173+
171174
void movdbl(XMMRegister dst, XMMRegister src) {
172175
if (dst-> encoding() == src->encoding()) return;
173176
if (UseXmmRegToRegMoveAll) { movapd(dst, src); return; }

src/hotspot/cpu/x86/x86.ad

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3375,7 +3375,7 @@ instruct reinterpret_shrink(vec dst, legVec src) %{
33753375
format %{ "vector_reinterpret_shrink $dst,$src\t!" %}
33763376
ins_encode %{
33773377
switch (vector_length_in_bytes(this)) {
3378-
case 4: __ movflt ($dst$$XMMRegister, $src$$XMMRegister); break;
3378+
case 4: __ movfltz($dst$$XMMRegister, $src$$XMMRegister); break;
33793379
case 8: __ movq ($dst$$XMMRegister, $src$$XMMRegister); break;
33803380
case 16: __ movdqu ($dst$$XMMRegister, $src$$XMMRegister); break;
33813381
case 32: __ vmovdqu($dst$$XMMRegister, $src$$XMMRegister); break;
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (C) 2021 THL A29 Limited, a Tencent company. 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.ByteVector;
27+
import jdk.incubator.vector.VectorOperators;
28+
import jdk.incubator.vector.VectorSpecies;
29+
30+
/*
31+
* @test
32+
* @bug 8259775
33+
* @summary Incorrect code-gen for VectorReinterpret operation
34+
* @modules jdk.incubator.vector
35+
* @run main/othervm -Xbatch compiler.vectorapi.VectorReinterpretTest
36+
*/
37+
38+
public class VectorReinterpretTest {
39+
static final VectorSpecies<Byte> SPECIES_128 = ByteVector.SPECIES_128;
40+
static final VectorSpecies<Byte> SPECIES_256 = ByteVector.SPECIES_256;
41+
static final VectorSpecies<Byte> SPECIES_512 = ByteVector.SPECIES_512;
42+
43+
static byte[] a = new byte[64];
44+
45+
private static void test256_128_256() {
46+
ByteVector av = ByteVector.fromArray(SPECIES_256, a, 0);
47+
ByteVector bv = (ByteVector)av.reinterpretShape(SPECIES_128, 0);
48+
ByteVector cv = (ByteVector)bv.reinterpretShape(SPECIES_256, 0);
49+
50+
if (bv.reduceLanes(VectorOperators.ADD) != 16 ||
51+
cv.reduceLanes(VectorOperators.ADD) != 16) {
52+
throw new Error("Failed");
53+
}
54+
}
55+
56+
private static void test512_256_512() {
57+
ByteVector av = ByteVector.fromArray(SPECIES_512, a, 0);
58+
ByteVector bv = (ByteVector)av.reinterpretShape(SPECIES_256, 0);
59+
ByteVector cv = (ByteVector)bv.reinterpretShape(SPECIES_512, 0);
60+
61+
if (bv.reduceLanes(VectorOperators.ADD) != 32 ||
62+
cv.reduceLanes(VectorOperators.ADD) != 32) {
63+
throw new Error("Failed");
64+
}
65+
}
66+
67+
public static void main(String[] args) {
68+
for (int i = 0; i < a.length; i++) {
69+
a[i] = 1;
70+
}
71+
72+
for (int i = 0; i < 100000; i++) {
73+
test256_128_256();
74+
test512_256_512();
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)