From 9e74df5fef23a825b33d72ce07080761c359b3d6 Mon Sep 17 00:00:00 2001 From: Jasmine Karthikeyan <25208576+jaskarth@users.noreply.github.com> Date: Mon, 26 Jan 2026 22:01:24 -0500 Subject: [PATCH] Apply changes from review --- src/hotspot/share/opto/superword.hpp | 2 +- .../share/opto/superwordVTransformBuilder.cpp | 3 ++- src/hotspot/share/opto/vectornode.cpp | 2 +- src/hotspot/share/opto/vectornode.hpp | 2 +- src/hotspot/share/opto/vtransform.cpp | 20 ++----------------- src/hotspot/share/opto/vtransform.hpp | 19 ------------------ .../jtreg/compiler/c2/TestMinMaxSubword.java | 11 +++++----- .../TestCompatibleUseDefTypeSize.java | 4 ++-- .../loopopts/superword/TestReductions.java | 8 ++++---- .../TestRotateByteAndShortVector.java | 3 ++- .../vectorization/TestSubwordTruncation.java | 4 ++-- .../runner/ArrayTypeConvertTest.java | 2 +- .../runner/BasicShortOpTest.java | 6 ++++-- .../bench/vm/compiler/VectorSubword.java | 2 +- 14 files changed, 29 insertions(+), 59 deletions(-) diff --git a/src/hotspot/share/opto/superword.hpp b/src/hotspot/share/opto/superword.hpp index 328cdb9c3cd..4e6fce70e5c 100644 --- a/src/hotspot/share/opto/superword.hpp +++ b/src/hotspot/share/opto/superword.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 diff --git a/src/hotspot/share/opto/superwordVTransformBuilder.cpp b/src/hotspot/share/opto/superwordVTransformBuilder.cpp index fd7f0940680..f8b8bfe2ed0 100644 --- a/src/hotspot/share/opto/superwordVTransformBuilder.cpp +++ b/src/hotspot/share/opto/superwordVTransformBuilder.cpp @@ -261,7 +261,8 @@ VTransformNode* SuperWordVTransformBuilder::get_or_make_vtnode_vector_input_at_i // If the use and def types are different, emit a cast node if (use_bt != def_bt && !p0->is_Convert() && VectorCastNode::is_supported_subword_cast(def_bt, use_bt, pack->size())) { VTransformNode* in = get_vtnode(pack_in->at(0)); - VTransformNode* cast = new (_vtransform.arena()) VTransformCastVectorNode(_vtransform, pack->size(), def_bt, use_bt); + const VTransformVectorNodeProperties properties = VTransformVectorNodeProperties::make_from_pack(pack, _vloop_analyzer); + VTransformNode* cast = new (_vtransform.arena()) VTransformElementWiseVectorNode(_vtransform, 2, properties, VectorCastNode::opcode(-1, def_bt)); cast->set_req(1, in); return cast; diff --git a/src/hotspot/share/opto/vectornode.cpp b/src/hotspot/share/opto/vectornode.cpp index f98640ae57a..6c21e5f4a46 100644 --- a/src/hotspot/share/opto/vectornode.cpp +++ b/src/hotspot/share/opto/vectornode.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 diff --git a/src/hotspot/share/opto/vectornode.hpp b/src/hotspot/share/opto/vectornode.hpp index 8fe96bcc622..4f614565dcc 100644 --- a/src/hotspot/share/opto/vectornode.hpp +++ b/src/hotspot/share/opto/vectornode.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 diff --git a/src/hotspot/share/opto/vtransform.cpp b/src/hotspot/share/opto/vtransform.cpp index aa416cb9595..93aefe0d505 100644 --- a/src/hotspot/share/opto/vtransform.cpp +++ b/src/hotspot/share/opto/vtransform.cpp @@ -1310,7 +1310,8 @@ bool VTransformReductionVectorNode::optimize_move_non_strict_order_reductions_ou return false; // not compatible } - if (current_red->in_req(2)->isa_Vector() == nullptr && current_red->in_req(2)->isa_CastVector() == nullptr) { + VTransformVectorNode* vector_input = current_red->in_req(2)->isa_Vector(); + if (vector_input == nullptr) { assert(false, "reduction has a bad vector input"); return false; } @@ -1540,24 +1541,11 @@ VTransformApplyResult VTransformStoreVectorNode::apply(VTransformApplyState& app return VTransformApplyResult::make_vector(vn, vn->vect_type()); } -float VTransformCastVectorNode::cost(const VLoopAnalyzer& vloop_analyzer) const { - return vloop_analyzer.cost_for_vector_node(VectorCastNode::opcode(-1, _from_bt), _vlen, _from_bt); -} - -VTransformApplyResult VTransformCastVectorNode::apply(VTransformApplyState& apply_state) const { - Node* value = apply_state.transformed_node(in_req(1)); - VectorNode* vn = VectorCastNode::make(VectorCastNode::opcode(-1, _from_bt), value, _to_bt, _vlen); - register_new_node_from_vectorization(apply_state, vn); - - return VTransformApplyResult::make_vector(vn, vn->vect_type()); -} - void VTransformNode::register_new_node_from_vectorization(VTransformApplyState& apply_state, Node* vn) const { PhaseIdealLoop* phase = apply_state.phase(); // Using the cl is sometimes not the most accurate, but still correct. We do not have to be // perfectly accurate, because we will set major_progress anyway. phase->register_new_node(vn, apply_state.vloop().cl()); - phase->igvn()._worklist.push(vn); VectorNode::trace_new_vector(vn, "AutoVectorization"); } @@ -1658,10 +1646,6 @@ void VTransformPopulateIndexNode::print_spec() const { tty->print("vlen=%d element_bt=%s", _vlen, type2name(_element_bt)); } -void VTransformCastVectorNode::print_spec() const { - tty->print("vlen=%d from=%s to=%s", _vlen, type2name(_from_bt), type2name(_to_bt)); -} - void VTransformVectorNode::print_spec() const { tty->print("Properties[orig=[%d %s] sopc=%s vlen=%d element_bt=%s]", approximate_origin()->_idx, diff --git a/src/hotspot/share/opto/vtransform.hpp b/src/hotspot/share/opto/vtransform.hpp index 3ce663dec8b..2c535eca6d1 100644 --- a/src/hotspot/share/opto/vtransform.hpp +++ b/src/hotspot/share/opto/vtransform.hpp @@ -93,7 +93,6 @@ class VTransformPhiVectorNode; class VTransformMemVectorNode; class VTransformLoadVectorNode; class VTransformStoreVectorNode; -class VTransformCastVectorNode; // Result from VTransformNode::apply class VTransformApplyResult { @@ -588,7 +587,6 @@ public: virtual VTransformMemVectorNode* isa_MemVector() { return nullptr; } virtual VTransformLoadVectorNode* isa_LoadVector() { return nullptr; } virtual VTransformStoreVectorNode* isa_StoreVector() { return nullptr; } - virtual VTransformCastVectorNode* isa_CastVector() { return nullptr; } virtual bool is_load_in_loop() const { return false; } virtual bool is_load_or_store_in_loop() const { return false; } @@ -978,21 +976,4 @@ public: NOT_PRODUCT(virtual const char* name() const override { return "StoreVector"; };) }; -class VTransformCastVectorNode : public VTransformNode { -private: - uint _vlen; - BasicType _from_bt; - BasicType _to_bt; - -public: - // req = 2 -> [ctrl, input] - VTransformCastVectorNode(VTransform& vtransform, int vlen, BasicType from_bt, BasicType to_bt) : VTransformNode(vtransform, 2), - _vlen(vlen), _from_bt(from_bt), _to_bt(to_bt) {} - virtual VTransformCastVectorNode* isa_CastVector() override { return this; } - virtual VTransformApplyResult apply(VTransformApplyState& apply_state) const override; - virtual float cost(const VLoopAnalyzer& vloop_analyzer) const override; - NOT_PRODUCT(virtual const char* name() const override { return "CastVector"; };) - NOT_PRODUCT(virtual void print_spec() const override;) -}; - #endif // SHARE_OPTO_VTRANSFORM_HPP diff --git a/test/hotspot/jtreg/compiler/c2/TestMinMaxSubword.java b/test/hotspot/jtreg/compiler/c2/TestMinMaxSubword.java index bf938a397e7..6b93f00cdb1 100644 --- a/test/hotspot/jtreg/compiler/c2/TestMinMaxSubword.java +++ b/test/hotspot/jtreg/compiler/c2/TestMinMaxSubword.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2022, Arm Limited. All rights reserved. + * 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 @@ -30,7 +31,7 @@ import java.util.Random; /* * @test - * @bug 8294816 + * @bug 8294816 8342095 * @key randomness * @summary Test Math.min/max vectorization miscompilation for integer subwords * @library /test/lib / @@ -62,7 +63,7 @@ public class TestMinMaxSubword { // types and superword should generate int versions and then cast between them. @Test - @IR(applyIfCPUFeature = { "avx", "true" }, counts = { IRNode.VECTOR_CAST_I2S, IRNode.VECTOR_SIZE_ANY, ">0" }) + @IR(applyIfCPUFeature = { "avx", "true" }, counts = { IRNode.VECTOR_CAST_I2S, IRNode.VECTOR_SIZE + "min(max_int, max_short)", ">0" }) public static void testMinShort() { for (int i = 0; i < LENGTH; i++) { sb[i] = (short) Math.min(sa[i], val); @@ -78,7 +79,7 @@ public class TestMinMaxSubword { } @Test - @IR(applyIfCPUFeature = { "avx", "true" }, counts = { IRNode.VECTOR_CAST_I2S, IRNode.VECTOR_SIZE_ANY, ">0" }) + @IR(applyIfCPUFeature = { "avx", "true" }, counts = { IRNode.VECTOR_CAST_I2S, IRNode.VECTOR_SIZE + "min(max_int, max_short)", ">0" }) public static void testMaxShort() { for (int i = 0; i < LENGTH; i++) { sb[i] = (short) Math.max(sa[i], val); @@ -93,7 +94,7 @@ public class TestMinMaxSubword { } @Test - @IR(applyIfCPUFeature = { "avx", "true" }, counts = { IRNode.VECTOR_CAST_I2B, IRNode.VECTOR_SIZE_ANY, ">0" }) + @IR(applyIfCPUFeature = { "avx", "true" }, counts = { IRNode.VECTOR_CAST_I2B, IRNode.VECTOR_SIZE + "min(max_int, max_byte)", ">0" }) public static void testMinByte() { for (int i = 0; i < LENGTH; i++) { bb[i] = (byte) Math.min(ba[i], val); @@ -109,7 +110,7 @@ public class TestMinMaxSubword { } @Test - @IR(applyIfCPUFeature = { "avx", "true" }, counts = { IRNode.VECTOR_CAST_I2B, IRNode.VECTOR_SIZE_ANY, ">0" }) + @IR(applyIfCPUFeature = { "avx", "true" }, counts = { IRNode.VECTOR_CAST_I2B, IRNode.VECTOR_SIZE + "min(max_int, max_byte)", ">0" }) public static void testMaxByte() { for (int i = 0; i < LENGTH; i++) { bb[i] = (byte) Math.max(ba[i], val); diff --git a/test/hotspot/jtreg/compiler/loopopts/superword/TestCompatibleUseDefTypeSize.java b/test/hotspot/jtreg/compiler/loopopts/superword/TestCompatibleUseDefTypeSize.java index 6836d325778..7399a1ec411 100644 --- a/test/hotspot/jtreg/compiler/loopopts/superword/TestCompatibleUseDefTypeSize.java +++ b/test/hotspot/jtreg/compiler/loopopts/superword/TestCompatibleUseDefTypeSize.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 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 @@ -34,7 +34,7 @@ import java.nio.ByteOrder; /* * @test - * @bug 8325155 + * @bug 8325155 8342095 * @key randomness * @summary Test some cases that vectorize after the removal of the alignment boundaries code. * Now, we instead check if use-def connections have compatible type size. diff --git a/test/hotspot/jtreg/compiler/loopopts/superword/TestReductions.java b/test/hotspot/jtreg/compiler/loopopts/superword/TestReductions.java index 6821b6272bd..97f32c14027 100644 --- a/test/hotspot/jtreg/compiler/loopopts/superword/TestReductions.java +++ b/test/hotspot/jtreg/compiler/loopopts/superword/TestReductions.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 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 @@ -23,7 +23,7 @@ /* * @test id=no-vectorization - * @bug 8340093 + * @bug 8340093 8342095 * @summary Test vectorization of reduction loops. * @library /test/lib / * @run driver compiler.loopopts.superword.TestReductions P0 @@ -31,7 +31,7 @@ /* * @test id=vanilla - * @bug 8340093 + * @bug 8340093 8342095 * @summary Test vectorization of reduction loops. * @library /test/lib / * @run driver compiler.loopopts.superword.TestReductions P1 @@ -39,7 +39,7 @@ /* * @test id=force-vectorization - * @bug 8340093 + * @bug 8340093 8342095 * @summary Test vectorization of reduction loops. * @library /test/lib / * @run driver compiler.loopopts.superword.TestReductions P2 diff --git a/test/hotspot/jtreg/compiler/vectorization/TestRotateByteAndShortVector.java b/test/hotspot/jtreg/compiler/vectorization/TestRotateByteAndShortVector.java index 7bcaaf535ac..79cde2f0d26 100644 --- a/test/hotspot/jtreg/compiler/vectorization/TestRotateByteAndShortVector.java +++ b/test/hotspot/jtreg/compiler/vectorization/TestRotateByteAndShortVector.java @@ -1,6 +1,7 @@ /* * Copyright (c) 2022, 2025 Loongson Technology Co. Ltd. All rights reserved. * Copyright (c) 2025, Rivos Inc. All rights reserved. + * 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 @@ -24,7 +25,7 @@ /** * @test - * @bug 8286847 8353600 + * @bug 8286847 8353600 8342095 * @key randomness * @summary Test vectorization of rotate byte and short * @library /test/lib / diff --git a/test/hotspot/jtreg/compiler/vectorization/TestSubwordTruncation.java b/test/hotspot/jtreg/compiler/vectorization/TestSubwordTruncation.java index cf6251dfd7b..29331cc1845 100644 --- a/test/hotspot/jtreg/compiler/vectorization/TestSubwordTruncation.java +++ b/test/hotspot/jtreg/compiler/vectorization/TestSubwordTruncation.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.g * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,7 +29,7 @@ import compiler.lib.generators.*; /* * @test - * @bug 8350177 8362171 8369881 + * @bug 8350177 8362171 8369881 8342095 * @summary Ensure that truncation of subword vectors produces correct results * @library /test/lib / * @run driver compiler.vectorization.TestSubwordTruncation diff --git a/test/hotspot/jtreg/compiler/vectorization/runner/ArrayTypeConvertTest.java b/test/hotspot/jtreg/compiler/vectorization/runner/ArrayTypeConvertTest.java index 3b795d48e86..f9c5f6199f1 100644 --- a/test/hotspot/jtreg/compiler/vectorization/runner/ArrayTypeConvertTest.java +++ b/test/hotspot/jtreg/compiler/vectorization/runner/ArrayTypeConvertTest.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2022, 2023, Arm Limited. All rights reserved. - * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 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 diff --git a/test/hotspot/jtreg/compiler/vectorization/runner/BasicShortOpTest.java b/test/hotspot/jtreg/compiler/vectorization/runner/BasicShortOpTest.java index b81d90484f3..b957a00278a 100644 --- a/test/hotspot/jtreg/compiler/vectorization/runner/BasicShortOpTest.java +++ b/test/hotspot/jtreg/compiler/vectorization/runner/BasicShortOpTest.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2022, 2023, Arm Limited. All rights reserved. + * 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 @@ -23,6 +24,7 @@ /* * @test + * @bug 8183390 8342095 * @summary Vectorization test on basic short operations * @library /test/lib / * @@ -213,7 +215,7 @@ public class BasicShortOpTest extends VectorizationTestRunner { // Min/Max vectorization requires a cast from subword to int and back to subword, to avoid losing the higher order bits. @Test - @IR(applyIfCPUFeature = { "avx", "true" }, counts = { IRNode.VECTOR_CAST_I2S, IRNode.VECTOR_SIZE_ANY, ">0" }) + @IR(applyIfCPUFeature = { "avx", "true" }, counts = { IRNode.VECTOR_CAST_I2S, IRNode.VECTOR_SIZE + "min(max_int, max_short)", ">0" }) public short[] vectorMin() { short[] res = new short[SIZE]; for (int i = 0; i < SIZE; i++) { @@ -223,7 +225,7 @@ public class BasicShortOpTest extends VectorizationTestRunner { } @Test - @IR(applyIfCPUFeature = { "avx", "true" }, counts = { IRNode.VECTOR_CAST_I2S, IRNode.VECTOR_SIZE_ANY, ">0" }) + @IR(applyIfCPUFeature = { "avx", "true" }, counts = { IRNode.VECTOR_CAST_I2S, IRNode.VECTOR_SIZE + "min(max_int, max_short)", ">0" }) public short[] vectorMax() { short[] res = new short[SIZE]; for (int i = 0; i < SIZE; i++) { diff --git a/test/micro/org/openjdk/bench/vm/compiler/VectorSubword.java b/test/micro/org/openjdk/bench/vm/compiler/VectorSubword.java index 424220f7896..5ade452b875 100644 --- a/test/micro/org/openjdk/bench/vm/compiler/VectorSubword.java +++ b/test/micro/org/openjdk/bench/vm/compiler/VectorSubword.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * 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