diff --git a/src/hotspot/cpu/aarch64/aarch64.ad b/src/hotspot/cpu/aarch64/aarch64.ad index 0c85d426ea0..2fd41174dbb 100644 --- a/src/hotspot/cpu/aarch64/aarch64.ad +++ b/src/hotspot/cpu/aarch64/aarch64.ad @@ -2697,7 +2697,7 @@ static bool are_users_clone_compatible(Node* n, Node* m) { bool Matcher::pd_clone_node(Node* n, Node* m, Matcher::MStack& mstack) { if (is_vshift_con_pattern(n, m) || ((is_vector_bitwise_not_pattern(n, m) || - is_valid_sve_arith_imm_pattern(n, m)) && + is_valid_sve_arith_imm_pattern(n, m)) && are_users_clone_compatible(n, m)) || is_vector_mask_not_operand_in_andnot_pattern(n, m) || is_encode_and_store_pattern(n, m)) { diff --git a/test/hotspot/jtreg/compiler/c2/aarch64/TestSveClone.java b/test/hotspot/jtreg/compiler/c2/aarch64/TestSveClone.java new file mode 100644 index 00000000000..f1bd8d2099d --- /dev/null +++ b/test/hotspot/jtreg/compiler/c2/aarch64/TestSveClone.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2026, Microsoft 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 8386697 + * @summary Ensure that users of replicate nodes are clone compatible before folding + * @library /test/lib / + * @modules jdk.incubator.vector + * @requires vm.cpu.features ~= ".*sve.*" + * @run main/othervm --add-modules=jdk.incubator.vector -XX:-TieredCompilation + * -XX:CompileThreshold=100 -XX:-BackgroundCompilation + * -XX:CompileCommand=compileonly,${test.main.class}::test + * ${test.main.class} + */ + +package compiler.c2.aarch64; + +import jdk.incubator.vector.*; + +public class TestSveClone { + static final VectorSpecies SB = ByteVector.SPECIES_64; + + static long test() { + return ByteVector.broadcast(SB, (byte) -8) + .lanewise(VectorOperators.XOR, + ByteVector.broadcast(SB, (byte) 0), + ByteVector.fromArray(SB, new byte[8], 0) + .compare(VectorOperators.EQ, (byte) 0)) + .reduceLanesToLong(VectorOperators.OR); + } + + public static void main(String[] args) { + for (int i = 0; i < 20000; i++) { + test(); + } + IO.println("done"); + } +}