From 528f93f8cb9f1fb9c19f31ab80c8a546f47beed2 Mon Sep 17 00:00:00 2001 From: erifan Date: Wed, 24 Sep 2025 01:35:51 +0000 Subject: [PATCH] 8367391: Loss of precision on implicit conversion in vectornode.cpp Reviewed-by: chagedorn, roland --- src/hotspot/share/opto/vectornode.cpp | 4 +- .../vectorapi/VectorMaskFromLongTest.java | 56 ++++++++++--------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/hotspot/share/opto/vectornode.cpp b/src/hotspot/share/opto/vectornode.cpp index ae9ef552df4..d656bf3127b 100644 --- a/src/hotspot/share/opto/vectornode.cpp +++ b/src/hotspot/share/opto/vectornode.cpp @@ -439,8 +439,8 @@ bool VectorNode::is_maskall_type(const TypeLong* type, int vlen) { if (!type->is_con()) { return false; } - long mask = (-1ULL >> (64 - vlen)); - long bit = type->get_con() & mask; + jlong mask = (-1ULL >> (64 - vlen)); + jlong bit = type->get_con() & mask; return bit == 0 || bit == mask; } diff --git a/test/hotspot/jtreg/compiler/vectorapi/VectorMaskFromLongTest.java b/test/hotspot/jtreg/compiler/vectorapi/VectorMaskFromLongTest.java index a97ce2f9162..eaa6211efc5 100644 --- a/test/hotspot/jtreg/compiler/vectorapi/VectorMaskFromLongTest.java +++ b/test/hotspot/jtreg/compiler/vectorapi/VectorMaskFromLongTest.java @@ -23,7 +23,7 @@ /* * @test -* @bug 8356760 +* @bug 8356760 8367391 * @library /test/lib / * @summary Optimize VectorMask.fromLong for all-true/all-false cases * @modules jdk.incubator.vector @@ -173,92 +173,98 @@ public class VectorMaskFromLongTest { @Test @IR(counts = { IRNode.MASK_ALL, "= 0", - IRNode.VECTOR_LONG_TO_MASK, "> 0" }, + IRNode.VECTOR_LONG_TO_MASK, "= 2" }, applyIfCPUFeatureOr = { "sve2", "true", "avx512", "true", "rvv", "true" }) @IR(counts = { IRNode.REPLICATE_B, "= 0", IRNode.VECTOR_LONG_TO_MASK, "= 0" }, applyIfCPUFeatureAnd = { "asimd", "true", "sve", "false" }) @IR(counts = { IRNode.REPLICATE_B, "= 0", - IRNode.VECTOR_LONG_TO_MASK, "> 0" }, + IRNode.VECTOR_LONG_TO_MASK, "= 2" }, applyIfCPUFeatureAnd = { "avx2", "true", "avx512", "false" }) public static void testMaskFromLongByte() { - // Test the case where some but not all bits are set. - testMaskFromLong(B_SPECIES, (-1L >>> (64 - B_SPECIES.length()))-1); + // Test cases where some but not all bits are set. + testMaskFromLong(B_SPECIES, (-1L >>> (64 - B_SPECIES.length())) - 1); + testMaskFromLong(B_SPECIES, (-1L >>> (64 - B_SPECIES.length())) >>> 1); } @Test @IR(counts = { IRNode.MASK_ALL, "= 0", - IRNode.VECTOR_LONG_TO_MASK, "> 0" }, + IRNode.VECTOR_LONG_TO_MASK, "= 2" }, applyIfCPUFeatureOr = { "sve2", "true", "avx512", "true", "rvv", "true" }) @IR(counts = { IRNode.REPLICATE_S, "= 0", IRNode.VECTOR_LONG_TO_MASK, "= 0" }, applyIfCPUFeatureAnd = { "asimd", "true", "sve", "false" }) @IR(counts = { IRNode.REPLICATE_S, "= 0", - IRNode.VECTOR_LONG_TO_MASK, "> 0" }, + IRNode.VECTOR_LONG_TO_MASK, "= 2" }, applyIfCPUFeatureAnd = { "avx2", "true", "avx512", "false" }) public static void testMaskFromLongShort() { - // Test the case where some but not all bits are set. - testMaskFromLong(S_SPECIES, (-1L >>> (64 - S_SPECIES.length()))-1); + // Test cases where some but not all bits are set. + testMaskFromLong(S_SPECIES, (-1L >>> (64 - S_SPECIES.length())) - 1); + testMaskFromLong(S_SPECIES, (-1L >>> (64 - S_SPECIES.length())) >>> 1); } @Test @IR(counts = { IRNode.MASK_ALL, "= 0", - IRNode.VECTOR_LONG_TO_MASK, "> 0" }, + IRNode.VECTOR_LONG_TO_MASK, "= 2" }, applyIfCPUFeatureOr = { "sve2", "true", "avx512", "true", "rvv", "true" }) @IR(counts = { IRNode.REPLICATE_I, "= 0", IRNode.VECTOR_LONG_TO_MASK, "= 0" }, applyIfCPUFeatureAnd = { "asimd", "true", "sve", "false" }) @IR(counts = { IRNode.REPLICATE_I, "= 0", - IRNode.VECTOR_LONG_TO_MASK, "> 0" }, + IRNode.VECTOR_LONG_TO_MASK, "= 2" }, applyIfCPUFeatureAnd = { "avx2", "true", "avx512", "false" }) public static void testMaskFromLongInt() { - // Test the case where some but not all bits are set. - testMaskFromLong(I_SPECIES, (-1L >>> (64 - I_SPECIES.length()))-1); + // Test cases where some but not all bits are set. + testMaskFromLong(I_SPECIES, (-1L >>> (64 - I_SPECIES.length())) - 1); + testMaskFromLong(I_SPECIES, (-1L >>> (64 - I_SPECIES.length())) >>> 1); } @Test @IR(counts = { IRNode.MASK_ALL, "= 0", - IRNode.VECTOR_LONG_TO_MASK, "> 0" }, + IRNode.VECTOR_LONG_TO_MASK, "= 2" }, applyIfCPUFeatureOr = { "sve2", "true", "avx512", "true", "rvv", "true" }) @IR(counts = { IRNode.REPLICATE_L, "= 0", IRNode.VECTOR_LONG_TO_MASK, "= 0" }, applyIfCPUFeatureAnd = { "asimd", "true", "sve", "false" }) @IR(counts = { IRNode.REPLICATE_L, "= 0", - IRNode.VECTOR_LONG_TO_MASK, "> 0" }, + IRNode.VECTOR_LONG_TO_MASK, "= 2" }, applyIfCPUFeatureAnd = { "avx2", "true", "avx512", "false" }) public static void testMaskFromLongLong() { - // Test the case where some but not all bits are set. - testMaskFromLong(L_SPECIES, (-1L >>> (64 - L_SPECIES.length()))-1); + // Test cases where some but not all bits are set. + testMaskFromLong(L_SPECIES, (-1L >>> (64 - L_SPECIES.length())) - 1); + testMaskFromLong(L_SPECIES, (-1L >>> (64 - L_SPECIES.length())) >>> 1); } @Test @IR(counts = { IRNode.MASK_ALL, "= 0", - IRNode.VECTOR_LONG_TO_MASK, "> 0" }, + IRNode.VECTOR_LONG_TO_MASK, "= 2" }, applyIfCPUFeatureOr = { "sve2", "true", "avx512", "true", "rvv", "true" }) @IR(counts = { IRNode.REPLICATE_I, "= 0", IRNode.VECTOR_LONG_TO_MASK, "= 0" }, applyIfCPUFeatureAnd = { "asimd", "true", "sve", "false" }) @IR(counts = { IRNode.REPLICATE_I, "= 0", - IRNode.VECTOR_LONG_TO_MASK, "> 0" }, + IRNode.VECTOR_LONG_TO_MASK, "= 2" }, applyIfCPUFeatureAnd = { "avx2", "true", "avx512", "false" }) public static void testMaskFromLongFloat() { - // Test the case where some but not all bits are set. - testMaskFromLong(F_SPECIES, (-1L >>> (64 - F_SPECIES.length()))-1); + // Test cases where some but not all bits are set. + testMaskFromLong(F_SPECIES, (-1L >>> (64 - F_SPECIES.length())) - 1); + testMaskFromLong(F_SPECIES, (-1L >>> (64 - F_SPECIES.length())) >>> 1); } @Test @IR(counts = { IRNode.MASK_ALL, "= 0", - IRNode.VECTOR_LONG_TO_MASK, "> 0" }, + IRNode.VECTOR_LONG_TO_MASK, "= 2" }, applyIfCPUFeatureOr = { "sve2", "true", "avx512", "true", "rvv", "true" }) @IR(counts = { IRNode.REPLICATE_L, "= 0", IRNode.VECTOR_LONG_TO_MASK, "= 0" }, applyIfCPUFeatureAnd = { "asimd", "true", "sve", "false" }) @IR(counts = { IRNode.REPLICATE_L, "= 0", - IRNode.VECTOR_LONG_TO_MASK, "> 0" }, + IRNode.VECTOR_LONG_TO_MASK, "= 2" }, applyIfCPUFeatureAnd = { "avx2", "true", "avx512", "false" }) public static void testMaskFromLongDouble() { - // Test the case where some but not all bits are set. - testMaskFromLong(D_SPECIES, (-1L >>> (64 - D_SPECIES.length()))-1); + // Test cases where some but not all bits are set. + testMaskFromLong(D_SPECIES, (-1L >>> (64 - D_SPECIES.length())) - 1); + testMaskFromLong(D_SPECIES, (-1L >>> (64 - D_SPECIES.length())) >>> 1); } public static void main(String[] args) {