8181633: Vectorization fails for some multiplication with constant cases
authornjian
Tue, 20 Jun 2017 16:25:53 +0800
changeset 48136 c035fbb1beb4
parent 48135 feea6d82adc2
child 48137 0afc5f9eafef
8181633: Vectorization fails for some multiplication with constant cases Reviewed-by: kvn Contributed-by: yang.zhang@linaro.org
src/hotspot/share/opto/superword.cpp
src/hotspot/share/opto/superword.hpp
--- a/src/hotspot/share/opto/superword.cpp	Mon Nov 27 16:05:11 2017 -0800
+++ b/src/hotspot/share/opto/superword.cpp	Tue Jun 20 16:25:53 2017 +0800
@@ -1102,7 +1102,7 @@
   }
 
   if (isomorphic(s1, s2)) {
-    if (independent(s1, s2) || reduction(s1, s2)) {
+    if ((independent(s1, s2) && have_similar_inputs(s1, s2)) || reduction(s1, s2)) {
       if (!exists_at(s1, 0) && !exists_at(s2, 1)) {
         if (!s1->is_Mem() || are_adjacent_refs(s1, s2)) {
           int s1_align = alignment(s1);
@@ -1180,6 +1180,20 @@
   return independent_path(shallow, deep);
 }
 
+//--------------------------have_similar_inputs-----------------------
+// For a node pair (s1, s2) which is isomorphic and independent,
+// do s1 and s2 have similar input edges?
+bool SuperWord::have_similar_inputs(Node* s1, Node* s2) {
+  // assert(isomorphic(s1, s2) == true, "check isomorphic");
+  // assert(independent(s1, s2) == true, "check independent");
+  if (s1->req() > 1 && !s1->is_Store() && !s1->is_Load()) {
+    for (uint i = 1; i < s1->req(); i++) {
+      if (s1->in(i)->Opcode() != s2->in(i)->Opcode()) return false;
+    }
+  }
+  return true;
+}
+
 //------------------------------reduction---------------------------
 // Is there a data path between s1 and s2 and the nodes reductions?
 bool SuperWord::reduction(Node* s1, Node* s2) {
--- a/src/hotspot/share/opto/superword.hpp	Mon Nov 27 16:05:11 2017 -0800
+++ b/src/hotspot/share/opto/superword.hpp	Tue Jun 20 16:25:53 2017 +0800
@@ -442,6 +442,9 @@
   bool isomorphic(Node* s1, Node* s2);
   // Is there no data path from s1 to s2 or s2 to s1?
   bool independent(Node* s1, Node* s2);
+  // For a node pair (s1, s2) which is isomorphic and independent,
+  // do s1 and s2 have similar input edges?
+  bool have_similar_inputs(Node* s1, Node* s2);
   // Is there a data path between s1 and s2 and both are reductions?
   bool reduction(Node* s1, Node* s2);
   // Helper for independent