From 6c5f1f619f654f233d1b6a0b8ce41eaa896a56e6 Mon Sep 17 00:00:00 2001 From: "Jin,Zhonghui" Date: Fri, 3 Nov 2023 00:00:39 +0800 Subject: [PATCH] [Backport] 8264104: Eliminate unnecessary vector mask conversion during VectorUnbox for floating point VectorMask Summary: 8264104: Eliminate unnecessary vector mask conversion during VectorUnbox for floating point VectorMask without new files in src/cpu/aarch64/ Test Plan: ci jtreg Reviewed-by: JoshuaZhuwj Issue: https://github.com/dragonwell-project/dragonwell11/issues/602 --- src/hotspot/share/adlc/formssel.cpp | 3 ++- src/hotspot/share/opto/classes.hpp | 1 + src/hotspot/share/opto/vectornode.cpp | 7 +++++++ src/hotspot/share/opto/vectornode.hpp | 11 +++++++++++ src/hotspot/share/runtime/vmStructs.cpp | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/adlc/formssel.cpp b/src/hotspot/share/adlc/formssel.cpp index 6363448dec8..64277008d8b 100644 --- a/src/hotspot/share/adlc/formssel.cpp +++ b/src/hotspot/share/adlc/formssel.cpp @@ -4201,7 +4201,8 @@ bool MatchRule::is_vector() const { "FmaVD", "FmaVF","PopCountVI", // Next are not supported currently. "PackB","PackS","PackI","PackL","PackF","PackD","Pack2L","Pack2D", - "ExtractB","ExtractUB","ExtractC","ExtractS","ExtractI","ExtractL","ExtractF","ExtractD" + "ExtractB","ExtractUB","ExtractC","ExtractS","ExtractI","ExtractL","ExtractF","ExtractD", + "VectorMaskCast" }; int cnt = sizeof(vector_list)/sizeof(char*); if (_rChild) { diff --git a/src/hotspot/share/opto/classes.hpp b/src/hotspot/share/opto/classes.hpp index 37aecbf0899..47182f66d70 100644 --- a/src/hotspot/share/opto/classes.hpp +++ b/src/hotspot/share/opto/classes.hpp @@ -430,6 +430,7 @@ macro(VectorBoxAllocate) macro(VectorUnbox) macro(VectorMaskWrapper) macro(VectorMaskCmp) +macro(VectorMaskCast) macro(VectorTest) macro(VectorBlend) macro(VectorRearrange) diff --git a/src/hotspot/share/opto/vectornode.cpp b/src/hotspot/share/opto/vectornode.cpp index c9fbe40401c..9975f2ab6e0 100644 --- a/src/hotspot/share/opto/vectornode.cpp +++ b/src/hotspot/share/opto/vectornode.cpp @@ -1095,6 +1095,13 @@ Node* VectorUnboxNode::Ideal(PhaseGVN* phase, bool can_reshape) { bool is_vector_mask = vbox_klass->is_subclass_of(ciEnv::current()->vector_VectorMask_klass()); bool is_vector_shuffle = vbox_klass->is_subclass_of(ciEnv::current()->vector_VectorShuffle_klass()); if (is_vector_mask) { + if (in_vt->length_in_bytes() == out_vt->length_in_bytes() && + Matcher::match_rule_supported_vector(Op_VectorMaskCast, out_vt->length(), out_vt->element_basic_type())) { + // Apply "VectorUnbox (VectorBox vmask) ==> VectorMaskCast (vmask)" + // directly. This could avoid the transformation ordering issue from + // "VectorStoreMask (VectorLoadMask vmask) => vmask". + return new VectorMaskCastNode(value, out_vt); + } // VectorUnbox (VectorBox vmask) ==> VectorLoadMask (VectorStoreMask vmask) value = phase->transform(VectorStoreMaskNode::make(*phase, value, in_vt->element_basic_type(), in_vt->length())); return new VectorLoadMaskNode(value, out_vt); diff --git a/src/hotspot/share/opto/vectornode.hpp b/src/hotspot/share/opto/vectornode.hpp index d2fd269616d..4362bf7f4e5 100644 --- a/src/hotspot/share/opto/vectornode.hpp +++ b/src/hotspot/share/opto/vectornode.hpp @@ -1215,6 +1215,17 @@ class VectorStoreMaskNode : public VectorNode { static VectorStoreMaskNode* make(PhaseGVN& gvn, Node* in, BasicType in_type, uint num_elem); }; +class VectorMaskCastNode : public VectorNode { + public: + VectorMaskCastNode(Node* in, const TypeVect* vt) : VectorNode(in, vt) { + const TypeVect* in_vt = in->bottom_type()->is_vect(); + assert(in_vt->length() == vt->length(), "vector length must match"); + assert(type2aelembytes(in_vt->element_basic_type()) == type2aelembytes(vt->element_basic_type()), "element size must match"); + } + + virtual int Opcode() const; +}; + // This is intended for use as a simple reinterpret node that has no cast. class VectorReinterpretNode : public VectorNode { private: diff --git a/src/hotspot/share/runtime/vmStructs.cpp b/src/hotspot/share/runtime/vmStructs.cpp index 480fc9be3c3..4b38536869f 100644 --- a/src/hotspot/share/runtime/vmStructs.cpp +++ b/src/hotspot/share/runtime/vmStructs.cpp @@ -1924,6 +1924,7 @@ typedef PaddedEnd PaddedObjectMonitor; declare_c2_type(VectorInsertNode, VectorNode) \ declare_c2_type(VectorUnboxNode, VectorNode) \ declare_c2_type(VectorReinterpretNode, VectorNode) \ + declare_c2_type(VectorMaskCastNode, VectorNode) \ declare_c2_type(VectorBoxNode, Node) \ declare_c2_type(VectorBoxAllocateNode, CallStaticJavaNode) \ declare_c2_type(VectorTestNode, Node) \