diff --git a/src/hotspot/cpu/x86/x86.ad b/src/hotspot/cpu/x86/x86.ad index 370437edee2..df035f39f58 100644 --- a/src/hotspot/cpu/x86/x86.ad +++ b/src/hotspot/cpu/x86/x86.ad @@ -3179,6 +3179,13 @@ bool Matcher::match_rule_supported(int opcode) { break; case Op_VectorCmpMasked: + if (!UseCountTrailingZerosInstruction) { + return false; + } + if (UseAVX < 3 || !VM_Version::supports_bmi2()) { + return false; + } + break; case Op_VectorMaskGen: if (UseAVX < 3 || !VM_Version::supports_bmi2()) { return false; diff --git a/test/hotspot/jtreg/compiler/cpuflags/TestUseCountTrailingZerosInstruction.java b/test/hotspot/jtreg/compiler/cpuflags/TestUseCountTrailingZerosInstruction.java new file mode 100644 index 00000000000..0c7d04486f2 --- /dev/null +++ b/test/hotspot/jtreg/compiler/cpuflags/TestUseCountTrailingZerosInstruction.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2026, 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. + */ + +/** + * @test + * @bug 8386656 + * @summary Verify no assertions when running with -XX:-UseCountTrailingZerosInstruction + * @requires os.simpleArch == "x64" + * @run main/othervm -Xbatch -XX:-UseCountTrailingZerosInstruction ${test.main.class} + */ + +/** + * @test + * @bug 8386656 + * @summary Verify no assertions when running with -XX:+UseCountTrailingZerosInstruction + * @requires os.simpleArch == "x64" + * @run main/othervm -Xbatch -XX:+UseCountTrailingZerosInstruction ${test.main.class} + */ + +package compiler.cpuflags; + +import java.util.Arrays; + +public class TestUseCountTrailingZerosInstruction { + public static void main(String[] args) { + byte[] a = new byte[32]; + byte[] b = new byte[32]; + for (int i = 0; i < 20_000; i++) { + Arrays.mismatch(a, b); + } + } +} +