Skip to content

Commit 55fd1ed

Browse files
author
Jatin Bhateja
committed
8333890: Fatal error in auto-vectorizer with float16 kernel.
Reviewed-by: kvn
1 parent 02956ab commit 55fd1ed

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/hotspot/share/opto/superword.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,6 +2586,12 @@ const Type* VLoopTypes::container_type(Node* n) const {
25862586
}
25872587
const Type* t = _vloop.phase()->igvn().type(n);
25882588
if (t->basic_type() == T_INT) {
2589+
// Float to half float conversion may be succeeded by a conversion from
2590+
// half float to float, in such a case back propagation of narrow type (SHORT)
2591+
// may not be possible.
2592+
if (n->Opcode() == Op_ConvF2HF) {
2593+
return TypeInt::SHORT;
2594+
}
25892595
// A narrow type of arithmetic operations will be determined by
25902596
// propagating the type of memory operations.
25912597
return TypeInt::INT;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. 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+
/**
25+
* @test
26+
* @summary Test Float16 vector conversion chain.
27+
* @requires vm.compiler2.enabled
28+
* @library /test/lib /
29+
* @run driver compiler.vectorization.TestFloat16VectorConvChain
30+
*/
31+
32+
package compiler.vectorization;
33+
34+
import compiler.lib.ir_framework.*;
35+
import java.util.Random;
36+
import java.util.Arrays;
37+
38+
39+
public class TestFloat16VectorConvChain {
40+
41+
@Test
42+
@IR(counts = {IRNode.VECTOR_CAST_HF2F, IRNode.VECTOR_SIZE_ANY, ">= 1", IRNode.VECTOR_CAST_F2HF, IRNode.VECTOR_SIZE_ANY, " >= 1"})
43+
public static void test(short [] res, short [] src1, short [] src2) {
44+
for (int i = 0; i < res.length; i++) {
45+
res[i] = (short)Float.float16ToFloat(Float.floatToFloat16(Float.float16ToFloat(src1[i]) + Float.float16ToFloat(src2[i])));
46+
}
47+
}
48+
49+
@Run(test = {"test"})
50+
@Warmup(1000)
51+
public static void micro() {
52+
short [] res = new short[1024];
53+
short [] src1 = new short[1024];
54+
short [] src2 = new short[1024];
55+
Arrays.fill(src1, (short)Float.floatToFloat16(1.0f));
56+
Arrays.fill(src2, (short)Float.floatToFloat16(2.0f));
57+
for (int i = 0; i < 1000; i++) {
58+
test(res, src1, src2);
59+
}
60+
}
61+
62+
public static void main(String [] args) {
63+
TestFramework.run(TestFloat16VectorConvChain.class);
64+
}
65+
}

0 commit comments

Comments
 (0)