@@ -936,28 +936,26 @@ bool VectorNode::is_scalar_op_that_returns_int_but_vector_op_returns_long(int op
936936 }
937937}
938938
939+ // Idealize vector operations whose vector size is less than the hardware supported
940+ // max vector size. Generate a vector mask for the operation. Lanes with indices
941+ // inside of the vector size are set to true, while the remaining lanes are set to
942+ // false. Returns the corresponding masked vector node.
943+ static Node* ideal_partial_operations (PhaseGVN* phase, Node* node, const TypeVect* vt) {
944+ if (!Matcher::vector_needs_partial_operations (node, vt)) {
945+ return nullptr ;
946+ }
939947
940- Node* VectorNode::try_to_gen_masked_vector (PhaseGVN* gvn, Node* node, const TypeVect* vt) {
941948 int vopc = node->Opcode ();
942949 uint vlen = vt->length ();
943950 BasicType bt = vt->element_basic_type ();
951+ assert (Matcher::match_rule_supported_vector_masked (vopc, vlen, bt),
952+ " The masked feature is required for the vector operation" );
953+ assert (Matcher::match_rule_supported_vector (Op_VectorMaskGen, vlen, bt),
954+ " 'VectorMaskGen' is required to generate a vector mask" );
944955
945- // Predicated vectors do not need to add another mask input
946- if (node->is_predicated_vector () || !Matcher::has_predicated_vectors () ||
947- !Matcher::match_rule_supported_vector_masked (vopc, vlen, bt) ||
948- !Matcher::match_rule_supported_vector (Op_VectorMaskGen, vlen, bt)) {
949- return nullptr ;
950- }
951-
952- Node* mask = nullptr ;
953- // Generate a vector mask for vector operation whose vector length is lower than the
954- // hardware supported max vector length.
955- if (vt->length_in_bytes () < (uint)MaxVectorSize) {
956- Node* length = gvn->transform (new ConvI2LNode (gvn->makecon (TypeInt::make (vlen))));
957- mask = gvn->transform (VectorMaskGenNode::make (length, bt, vlen));
958- } else {
959- return nullptr ;
960- }
956+ // Generate a vector mask, with lanes inside of the vector length set to true.
957+ Node* length = phase->transform (new ConvI2LNode (phase->makecon (TypeInt::make (vlen))));
958+ Node* mask = phase->transform (VectorMaskGenNode::make (length, bt, vlen));
961959
962960 // Generate the related masked op for vector load/store/load_gather/store_scatter.
963961 // Or append the mask to the vector op's input list by default.
@@ -1037,8 +1035,9 @@ bool VectorNode::should_swap_inputs_to_help_global_value_numbering() {
10371035}
10381036
10391037Node* VectorNode::Ideal (PhaseGVN* phase, bool can_reshape) {
1040- if (Matcher::vector_needs_partial_operations (this , vect_type ())) {
1041- return try_to_gen_masked_vector (phase, this , vect_type ());
1038+ Node* n = ideal_partial_operations (phase, this , vect_type ());
1039+ if (n != nullptr ) {
1040+ return n;
10421041 }
10431042
10441043 // Sort inputs of commutative non-predicated vector operations to help value numbering.
@@ -1119,9 +1118,9 @@ LoadVectorNode* LoadVectorNode::make(int opc, Node* ctl, Node* mem,
11191118}
11201119
11211120Node* LoadVectorNode::Ideal (PhaseGVN* phase, bool can_reshape) {
1122- const TypeVect* vt = vect_type ();
1123- if (Matcher::vector_needs_partial_operations ( this , vt) ) {
1124- return VectorNode::try_to_gen_masked_vector (phase, this , vt) ;
1121+ Node* n = ideal_partial_operations (phase, this , vect_type () );
1122+ if (n != nullptr ) {
1123+ return n ;
11251124 }
11261125 return LoadNode::Ideal (phase, can_reshape);
11271126}
@@ -1133,9 +1132,9 @@ StoreVectorNode* StoreVectorNode::make(int opc, Node* ctl, Node* mem, Node* adr,
11331132}
11341133
11351134Node* StoreVectorNode::Ideal (PhaseGVN* phase, bool can_reshape) {
1136- const TypeVect* vt = vect_type ();
1137- if (Matcher::vector_needs_partial_operations ( this , vt) ) {
1138- return VectorNode::try_to_gen_masked_vector (phase, this , vt) ;
1135+ Node* n = ideal_partial_operations (phase, this , vect_type () );
1136+ if (n != nullptr ) {
1137+ return n ;
11391138 }
11401139 return StoreNode::Ideal (phase, can_reshape);
11411140}
@@ -1411,11 +1410,11 @@ ReductionNode* ReductionNode::make(int opc, Node* ctrl, Node* n1, Node* n2, Basi
14111410}
14121411
14131412Node* ReductionNode::Ideal (PhaseGVN* phase, bool can_reshape) {
1414- const TypeVect* vt = vect_type ();
1415- if (Matcher::vector_needs_partial_operations ( this , vt) ) {
1416- return VectorNode::try_to_gen_masked_vector (phase, this , vt) ;
1413+ Node* n = ideal_partial_operations (phase, this , vect_type () );
1414+ if (n != nullptr ) {
1415+ return n ;
14171416 }
1418- return nullptr ;
1417+ return Node::Ideal (phase, can_reshape) ;
14191418}
14201419
14211420// Convert fromLong to maskAll if the input sets or unsets all lanes.
@@ -1893,11 +1892,11 @@ Node* VectorMaskOpNode::make(Node* mask, const Type* ty, int mopc) {
18931892}
18941893
18951894Node* VectorMaskOpNode::Ideal (PhaseGVN* phase, bool can_reshape) {
1896- const TypeVect* vt = vect_type ();
1897- if (Matcher::vector_needs_partial_operations ( this , vt) ) {
1898- return VectorNode::try_to_gen_masked_vector (phase, this , vt) ;
1895+ Node* n = ideal_partial_operations (phase, this , vect_type () );
1896+ if (n != nullptr ) {
1897+ return n ;
18991898 }
1900- return nullptr ;
1899+ return TypeNode::Ideal (phase, can_reshape) ;
19011900}
19021901
19031902Node* VectorMaskCastNode::Identity (PhaseGVN* phase) {
0 commit comments