From 548a95379f159a0dc369f6bb80d8167ec835c7cd Mon Sep 17 00:00:00 2001 From: Jatin Bhateja Date: Sat, 27 Jun 2026 01:46:53 +0000 Subject: [PATCH] 8386163: C2 Vector API: assert(collect_unique_inputs(n, inputs) == 1) failed: not unary Reviewed-by: vlivanov, epeter --- src/hotspot/share/opto/compile.cpp | 12 ++- .../vectorapi/TestMaskedNotAllOnes.java | 84 +++++++++++++++++++ 2 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/vectorapi/TestMaskedNotAllOnes.java diff --git a/src/hotspot/share/opto/compile.cpp b/src/hotspot/share/opto/compile.cpp index e283d9b97ad..a2e5899a1e9 100644 --- a/src/hotspot/share/opto/compile.cpp +++ b/src/hotspot/share/opto/compile.cpp @@ -2721,13 +2721,11 @@ static uint collect_unique_inputs(Node* n, Unique_Node_List& inputs) { if (is_vector_bitwise_op(n)) { uint inp_cnt = n->is_predicated_vector() ? n->req()-1 : n->req(); if (VectorNode::is_vector_bitwise_not_pattern(n)) { - for (uint i = 1; i < inp_cnt; i++) { - Node* in = n->in(i); - bool skip = VectorNode::is_all_ones_vector(in); - if (!skip && !inputs.member(in)) { - inputs.push(in); - cnt++; - } + assert(n->req() == (n->is_predicated_vector() ? 4 : 3), "must have 2 data inputs"); + Node* opnd = VectorNode::is_all_ones_vector(n->in(1)) ? n->in(2) : n->in(1); + if (!inputs.member(opnd)) { + inputs.push(opnd); + cnt++; } assert(cnt <= 1, "not unary"); } else { diff --git a/test/hotspot/jtreg/compiler/vectorapi/TestMaskedNotAllOnes.java b/test/hotspot/jtreg/compiler/vectorapi/TestMaskedNotAllOnes.java new file mode 100644 index 00000000000..6abf88ed06f --- /dev/null +++ b/test/hotspot/jtreg/compiler/vectorapi/TestMaskedNotAllOnes.java @@ -0,0 +1,84 @@ +/* + * 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 8386163 + * @summary Checks there is no assertion failure with macro logic optimization when both inputs of not patterns are all one vectors + * @modules jdk.incubator.vector + * @library /test/lib / + * @run driver ${test.main.class} + */ + +package compiler.vectorapi; + +import compiler.lib.ir_framework.*; +import compiler.lib.verify.Verify; +import jdk.incubator.vector.IntVector; +import jdk.incubator.vector.VectorMask; +import jdk.incubator.vector.VectorOperators; +import jdk.incubator.vector.VectorSpecies; + +public class TestMaskedNotAllOnes { + + private static final VectorSpecies ISP = IntVector.SPECIES_PREFERRED; + private static final int VALUE = 1234567; + + public static void main(String[] args) { + TestFramework.runWithFlags("--add-modules=jdk.incubator.vector"); + } + + @Test + @Warmup(10000) + static int[] testMaskedDivNegOne() { + IntVector v = IntVector.broadcast(ISP, VALUE); + VectorMask mask = VectorMask.fromLong(ISP, -1L); + int[] out = new int[ISP.length()]; + v.div(-1, mask).intoArray(out, 0); + return out; + } + + static final int[] GOLD_DIV = testMaskedDivNegOne(); + + @Check(test = "testMaskedDivNegOne") + static void checkMaskedDivNegOne(int[] out) { + Verify.checkEQ(GOLD_DIV, out); + } + + @Test + @Warmup(10000) + static int[] testMaskedNotAllOnesVector() { + IntVector allOnes = IntVector.broadcast(ISP, -1); + VectorMask mask = VectorMask.fromLong(ISP, -1L); + int[] out = new int[ISP.length()]; + allOnes.lanewise(VectorOperators.NOT, mask).intoArray(out, 0); + return out; + } + + static final int[] GOLD_NOT = testMaskedNotAllOnesVector(); + + @Check(test = "testMaskedNotAllOnesVector") + static void checkMaskedNotAllOnesVector(int[] out) { + Verify.checkEQ(GOLD_NOT, out); + } +}