From aa36799acb5834d730400fb073a9a3a8ee3c28ef Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Wed, 17 Sep 2025 21:34:15 +0000 Subject: [PATCH] 8367333: C2: Vector math operation intrinsification failure Reviewed-by: epeter, shade, jbhateja --- src/hotspot/share/prims/vectorSupport.cpp | 19 +++ src/hotspot/share/prims/vectorSupport.hpp | 19 +++ .../compiler/vectorapi/TestVectorMathLib.java | 129 ++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 test/hotspot/jtreg/compiler/vectorapi/TestVectorMathLib.java diff --git a/src/hotspot/share/prims/vectorSupport.cpp b/src/hotspot/share/prims/vectorSupport.cpp index 002f737e788..a98cad07227 100644 --- a/src/hotspot/share/prims/vectorSupport.cpp +++ b/src/hotspot/share/prims/vectorSupport.cpp @@ -592,6 +592,25 @@ int VectorSupport::vop2ideal(jint id, BasicType bt) { break; } + case VECTOR_OP_TAN: // fall-through + case VECTOR_OP_TANH: // fall-through + case VECTOR_OP_SIN: // fall-through + case VECTOR_OP_SINH: // fall-through + case VECTOR_OP_COS: // fall-through + case VECTOR_OP_COSH: // fall-through + case VECTOR_OP_ASIN: // fall-through + case VECTOR_OP_ACOS: // fall-through + case VECTOR_OP_ATAN: // fall-through + case VECTOR_OP_ATAN2: // fall-through + case VECTOR_OP_CBRT: // fall-through + case VECTOR_OP_LOG: // fall-through + case VECTOR_OP_LOG10: // fall-through + case VECTOR_OP_LOG1P: // fall-through + case VECTOR_OP_POW: // fall-through + case VECTOR_OP_EXP: // fall-through + case VECTOR_OP_EXPM1: // fall-through + case VECTOR_OP_HYPOT: return 0; // not supported; should be handled in Java code + default: fatal("unknown op: %d", vop); } return 0; // Unimplemented diff --git a/src/hotspot/share/prims/vectorSupport.hpp b/src/hotspot/share/prims/vectorSupport.hpp index 5ba18cdfaa8..9ec6500543c 100644 --- a/src/hotspot/share/prims/vectorSupport.hpp +++ b/src/hotspot/share/prims/vectorSupport.hpp @@ -101,6 +101,25 @@ class VectorSupport : AllStatic { VECTOR_OP_COMPRESS_BITS = 33, VECTOR_OP_EXPAND_BITS = 34, + VECTOR_OP_TAN = 101, + VECTOR_OP_TANH = 102, + VECTOR_OP_SIN = 103, + VECTOR_OP_SINH = 104, + VECTOR_OP_COS = 105, + VECTOR_OP_COSH = 106, + VECTOR_OP_ASIN = 107, + VECTOR_OP_ACOS = 108, + VECTOR_OP_ATAN = 109, + VECTOR_OP_ATAN2 = 110, + VECTOR_OP_CBRT = 111, + VECTOR_OP_LOG = 112, + VECTOR_OP_LOG10 = 113, + VECTOR_OP_LOG1P = 114, + VECTOR_OP_POW = 115, + VECTOR_OP_EXP = 116, + VECTOR_OP_EXPM1 = 117, + VECTOR_OP_HYPOT = 118, + VECTOR_OP_SADD = 119, VECTOR_OP_SSUB = 120, VECTOR_OP_SUADD = 121, diff --git a/test/hotspot/jtreg/compiler/vectorapi/TestVectorMathLib.java b/test/hotspot/jtreg/compiler/vectorapi/TestVectorMathLib.java new file mode 100644 index 00000000000..112220262b6 --- /dev/null +++ b/test/hotspot/jtreg/compiler/vectorapi/TestVectorMathLib.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2025, 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. + */ + +package compiler.vectorapi; + +import jdk.incubator.vector.FloatVector; +import jdk.incubator.vector.VectorOperators; +import jdk.incubator.vector.VectorSpecies; + +/* + * @test + * @bug 8367333 + * @requires vm.compiler2.enabled + * @modules jdk.incubator.vector + * @library /test/lib + * + * @run main/othervm -Xbatch -XX:-TieredCompilation -XX:+StressIncrementalInlining -XX:CompileCommand=quiet + * -XX:CompileCommand=compileonly,compiler.vectorapi.TestVectorMathLib::test* + * compiler.vectorapi.TestVectorMathLib + */ + +public class TestVectorMathLib { + private static final VectorSpecies SPECIES = FloatVector.SPECIES_PREFERRED; + + static FloatVector testTAN(FloatVector fv) { + return fv.lanewise(VectorOperators.TAN); + } + static FloatVector testTANH(FloatVector fv) { + return fv.lanewise(VectorOperators.TANH); + } + static FloatVector testSIN(FloatVector fv) { + return fv.lanewise(VectorOperators.SIN); + } + static FloatVector testSINH(FloatVector fv) { + return fv.lanewise(VectorOperators.SINH); + } + static FloatVector testCOS(FloatVector fv) { + return fv.lanewise(VectorOperators.COS); + } + static FloatVector testCOSH(FloatVector fv) { + return fv.lanewise(VectorOperators.COSH); + } + static FloatVector testASIN(FloatVector fv) { + return fv.lanewise(VectorOperators.ASIN); + } + static FloatVector testACOS(FloatVector fv) { + return fv.lanewise(VectorOperators.ACOS); + } + static FloatVector testATAN(FloatVector fv) { + return fv.lanewise(VectorOperators.ATAN); + } + static FloatVector testATAN2(FloatVector fv) { + return fv.lanewise(VectorOperators.ATAN2, fv); + } + static FloatVector testCBRT(FloatVector fv) { + return fv.lanewise(VectorOperators.CBRT); + } + static FloatVector testLOG(FloatVector fv) { + return fv.lanewise(VectorOperators.LOG); + } + static FloatVector testLOG10(FloatVector fv) { + return fv.lanewise(VectorOperators.LOG10); + } + static FloatVector testLOG1P(FloatVector fv) { + return fv.lanewise(VectorOperators.LOG1P); + } + static FloatVector testPOW(FloatVector fv) { + return fv.lanewise(VectorOperators.POW, fv); + } + static FloatVector testEXP(FloatVector fv) { + return fv.lanewise(VectorOperators.EXP); + } + static FloatVector testEXPM1(FloatVector fv) { + return fv.lanewise(VectorOperators.EXPM1); + } + static FloatVector testHYPOT(FloatVector fv) { + return fv.lanewise(VectorOperators.HYPOT, fv); + } + + public static void main(String[] args) { + FloatVector z = FloatVector.zero(SPECIES); + for (int i = 0; i < 20_000; i++) { + z.neg(); // unary + z.add(z); // binary + + testTAN(z); + testTANH(z); + testSIN(z); + testSINH(z); + testCOS(z); + testCOSH(z); + testASIN(z); + testACOS(z); + testATAN(z); + testATAN2(z); + testCBRT(z); + testLOG(z); + testLOG10(z); + testLOG1P(z); + testPOW(z); + testEXP(z); + testEXPM1(z); + testHYPOT(z); + } + + System.out.println("TEST PASSED"); + } +} +