< prev index next >

src/share/vm/opto/superword.cpp

Print this page
rev 13112 : 8181633: Vectorization fails for some multiplication with constant cases
Reviewed-by: duke
Contributed-by: yang.zhang@linaro.org


1053     assert(n->is_Mem(), "unexpected node %s", n->Name());
1054     n = n->in(MemNode::Memory);
1055   }
1056 }
1057 
1058 //------------------------------stmts_can_pack---------------------------
1059 // Can s1 and s2 be in a pack with s1 immediately preceding s2 and
1060 // s1 aligned at "align"
1061 bool SuperWord::stmts_can_pack(Node* s1, Node* s2, int align) {
1062 
1063   // Do not use superword for non-primitives
1064   BasicType bt1 = velt_basic_type(s1);
1065   BasicType bt2 = velt_basic_type(s2);
1066   if(!is_java_primitive(bt1) || !is_java_primitive(bt2))
1067     return false;
1068   if (Matcher::max_vector_size(bt1) < 2) {
1069     return false; // No vectors for this type
1070   }
1071 
1072   if (isomorphic(s1, s2)) {
1073     if (independent(s1, s2) || reduction(s1, s2)) {
1074       if (!exists_at(s1, 0) && !exists_at(s2, 1)) {
1075         if (!s1->is_Mem() || are_adjacent_refs(s1, s2)) {
1076           int s1_align = alignment(s1);
1077           int s2_align = alignment(s2);
1078           if (s1_align == top_align || s1_align == align) {
1079             if (s2_align == top_align || s2_align == align + data_size(s1)) {
1080               return true;
1081             }
1082           }
1083         }
1084       }
1085     }
1086   }
1087   return false;
1088 }
1089 
1090 //------------------------------exists_at---------------------------
1091 // Does s exist in a pack at position pos?
1092 bool SuperWord::exists_at(Node* s, uint pos) {
1093   for (int i = 0; i < _packset.length(); i++) {


1129   if (s1->Opcode() != s2->Opcode()) return false;
1130   if (s1->req() != s2->req()) return false;
1131   if (s1->in(0) != s2->in(0)) return false;
1132   if (!same_velt_type(s1, s2)) return false;
1133   return true;
1134 }
1135 
1136 //------------------------------independent---------------------------
1137 // Is there no data path from s1 to s2 or s2 to s1?
1138 bool SuperWord::independent(Node* s1, Node* s2) {
1139   //  assert(s1->Opcode() == s2->Opcode(), "check isomorphic first");
1140   int d1 = depth(s1);
1141   int d2 = depth(s2);
1142   if (d1 == d2) return s1 != s2;
1143   Node* deep    = d1 > d2 ? s1 : s2;
1144   Node* shallow = d1 > d2 ? s2 : s1;
1145 
1146   visited_clear();
1147 
1148   return independent_path(shallow, deep);














1149 }
1150 
1151 //------------------------------reduction---------------------------
1152 // Is there a data path between s1 and s2 and the nodes reductions?
1153 bool SuperWord::reduction(Node* s1, Node* s2) {
1154   bool retValue = false;
1155   int d1 = depth(s1);
1156   int d2 = depth(s2);
1157   if (d1 + 1 == d2) {
1158     if (s1->is_reduction() && s2->is_reduction()) {
1159       // This is an ordered set, so s1 should define s2
1160       for (DUIterator_Fast imax, i = s1->fast_outs(imax); i < imax; i++) {
1161         Node* t1 = s1->fast_out(i);
1162         if (t1 == s2) {
1163           // both nodes are reductions and connected
1164           retValue = true;
1165         }
1166       }
1167     }
1168   }




1053     assert(n->is_Mem(), "unexpected node %s", n->Name());
1054     n = n->in(MemNode::Memory);
1055   }
1056 }
1057 
1058 //------------------------------stmts_can_pack---------------------------
1059 // Can s1 and s2 be in a pack with s1 immediately preceding s2 and
1060 // s1 aligned at "align"
1061 bool SuperWord::stmts_can_pack(Node* s1, Node* s2, int align) {
1062 
1063   // Do not use superword for non-primitives
1064   BasicType bt1 = velt_basic_type(s1);
1065   BasicType bt2 = velt_basic_type(s2);
1066   if(!is_java_primitive(bt1) || !is_java_primitive(bt2))
1067     return false;
1068   if (Matcher::max_vector_size(bt1) < 2) {
1069     return false; // No vectors for this type
1070   }
1071 
1072   if (isomorphic(s1, s2)) {
1073     if ((independent(s1, s2) && have_similar_inputs(s1, s2)) || reduction(s1, s2)) {
1074       if (!exists_at(s1, 0) && !exists_at(s2, 1)) {
1075         if (!s1->is_Mem() || are_adjacent_refs(s1, s2)) {
1076           int s1_align = alignment(s1);
1077           int s2_align = alignment(s2);
1078           if (s1_align == top_align || s1_align == align) {
1079             if (s2_align == top_align || s2_align == align + data_size(s1)) {
1080               return true;
1081             }
1082           }
1083         }
1084       }
1085     }
1086   }
1087   return false;
1088 }
1089 
1090 //------------------------------exists_at---------------------------
1091 // Does s exist in a pack at position pos?
1092 bool SuperWord::exists_at(Node* s, uint pos) {
1093   for (int i = 0; i < _packset.length(); i++) {


1129   if (s1->Opcode() != s2->Opcode()) return false;
1130   if (s1->req() != s2->req()) return false;
1131   if (s1->in(0) != s2->in(0)) return false;
1132   if (!same_velt_type(s1, s2)) return false;
1133   return true;
1134 }
1135 
1136 //------------------------------independent---------------------------
1137 // Is there no data path from s1 to s2 or s2 to s1?
1138 bool SuperWord::independent(Node* s1, Node* s2) {
1139   //  assert(s1->Opcode() == s2->Opcode(), "check isomorphic first");
1140   int d1 = depth(s1);
1141   int d2 = depth(s2);
1142   if (d1 == d2) return s1 != s2;
1143   Node* deep    = d1 > d2 ? s1 : s2;
1144   Node* shallow = d1 > d2 ? s2 : s1;
1145 
1146   visited_clear();
1147 
1148   return independent_path(shallow, deep);
1149 }
1150 
1151 //--------------------------have_similar_inputs-----------------------
1152 // For a node pair (s1, s2) which is isomorphic and independent,
1153 // do s1 and s2 have similar input edges?
1154 bool SuperWord::have_similar_inputs(Node* s1, Node* s2) {
1155   // assert(isomorphic(s1, s2) == true, "check isomorphic");
1156   // assert(independent(s1, s2) == true, "check independent");
1157   if (s1->req() > 1 && !s1->is_Store() && !s1->is_Load()) {
1158     for (uint i = 1; i < s1->req(); i++) {
1159       if (s1->in(i)->Opcode() != s2->in(i)->Opcode()) return false;
1160     }
1161   }
1162   return true;
1163 }
1164 
1165 //------------------------------reduction---------------------------
1166 // Is there a data path between s1 and s2 and the nodes reductions?
1167 bool SuperWord::reduction(Node* s1, Node* s2) {
1168   bool retValue = false;
1169   int d1 = depth(s1);
1170   int d2 = depth(s2);
1171   if (d1 + 1 == d2) {
1172     if (s1->is_reduction() && s2->is_reduction()) {
1173       // This is an ordered set, so s1 should define s2
1174       for (DUIterator_Fast imax, i = s1->fast_outs(imax); i < imax; i++) {
1175         Node* t1 = s1->fast_out(i);
1176         if (t1 == s2) {
1177           // both nodes are reductions and connected
1178           retValue = true;
1179         }
1180       }
1181     }
1182   }


< prev index next >