From 6e6ec30f22037e358fefafa7981d4757037558e5 Mon Sep 17 00:00:00 2001 From: Ashay Rane <253344819+raneashay@users.noreply.github.com> Date: Mon, 20 Jul 2026 10:41:18 -0500 Subject: [PATCH] Ensure users of Replicate are clone compatible When replicate nodes appear in foldable SVE operations, we need to ensure prior to folding that all other users of the replicate nodes are also clone compatible, so that the replicate node is not matched two or more times. This patch fixes the failing test in test/hotspot/jtreg/compiler/vectorapi/TestMaskedNotAllOnes.java. --- src/hotspot/cpu/aarch64/aarch64.ad | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/hotspot/cpu/aarch64/aarch64.ad b/src/hotspot/cpu/aarch64/aarch64.ad index 37c8e0ae011..0c85d426ea0 100644 --- a/src/hotspot/cpu/aarch64/aarch64.ad +++ b/src/hotspot/cpu/aarch64/aarch64.ad @@ -2679,12 +2679,27 @@ static bool is_vector_mask_not_operand_in_andnot_pattern(Node* n, Node* m) { return false; } +static bool are_users_clone_compatible(Node* n, Node* m) { + for (DUIterator_Fast imax, i = m->fast_outs(imax); i < imax; i++) { + Node* use = m->fast_out(i); + if (use == n) { + continue; + } + if (!is_vector_bitwise_not_pattern(use, m) && + !is_valid_sve_arith_imm_pattern(use, m)) { + return false; + } + } + return true; +} + // Should the matcher clone input 'm' of node 'n'? 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_vector_bitwise_not_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_valid_sve_arith_imm_pattern(n, m) || is_encode_and_store_pattern(n, m)) { mstack.push(m, Visit); return true;