tree-vect-analyze.c (vect_analyze_operations): Reorganize calls to vectorizable_...
authorDorit Nuzman <dorit@il.ibm.com>
Mon, 16 Apr 2007 12:54:01 +0000 (12:54 +0000)
committerDorit Nuzman <dorit@gcc.gnu.org>
Mon, 16 Apr 2007 12:54:01 +0000 (12:54 +0000)
        * tree-vect-analyze.c (vect_analyze_operations): Reorganize calls to
        vectorizable_* functions.
        * tree-vect-transform.c (vectorizable_call): Add check for
        STMT_VINFO_RELEVANT_P, STMT_VINFO_DEF_TYPE and STMT_VINFO_LIVE_P.
        (vectorizable_store): likewise.
        (vectorizable_conversion): Add check for STMT_VINFO_DEF_TYPE.
        Add comments.
        (vectorizable_operation, vectorizable_type_demotion): Likewise.
        (vectorizable_type_promotion, vectorizable_load): Likewise.
        (vectorizable_live_operation, vectorizable_condition): Likewise.
        (vectorizable_assignment): Add check for STMT_VINFO_DEF_TYPE and
        STMT_VINFO_LIVE_P.
        (vect_transform_stmt): Reorganize calls to vectorizable_* functions.

From-SVN: r123861

gcc/ChangeLog
gcc/tree-vect-analyze.c
gcc/tree-vect-transform.c

index c9a8298550c05ff95b40af38392273c7ceca2425..ecce3615016e3273c7bae1f69d8b64fb1d068aed 100644 (file)
@@ -1,3 +1,19 @@
+2007-04-16  Dorit Nuzman  <dorit@il.ibm.com>
+
+       * tree-vect-analyze.c (vect_analyze_operations): Reorganize calls to
+       vectorizable_* functions.
+       * tree-vect-transform.c (vectorizable_call): Add check for
+       STMT_VINFO_RELEVANT_P, STMT_VINFO_DEF_TYPE and STMT_VINFO_LIVE_P.
+       (vectorizable_store): likewise.
+       (vectorizable_conversion): Add check for STMT_VINFO_DEF_TYPE.
+       Add comments.
+       (vectorizable_operation, vectorizable_type_demotion): Likewise.
+       (vectorizable_type_promotion, vectorizable_load): Likewise.
+       (vectorizable_live_operation, vectorizable_condition): Likewise.
+       (vectorizable_assignment): Add check for STMT_VINFO_DEF_TYPE and
+       STMT_VINFO_LIVE_P.
+       (vect_transform_stmt): Reorganize calls to vectorizable_* functions.
+
 2007-04-15  Kazu Hirata  <kazu@codesourcery.com>
 
        * config/m68k/linux.h (FUNCTION_VALUE_REGNO_P): Use macros for
index 7b3f4c8fd6fe86a33088c060cd23c5f67d365a4a..e7dff736325b98cebb309333aaca76c041162bf1 100644 (file)
@@ -325,8 +325,8 @@ vect_analyze_operations (loop_vec_info loop_vinfo)
              /* FORNOW: not yet supported.  */
              if (vect_print_dump_info (REPORT_UNVECTORIZED_LOOPS))
                fprintf (vect_dump, "not vectorized: value used after loop.");
-           return false;
-         }
+             return false;
+           }
 
          if (STMT_VINFO_RELEVANT (stmt_info) == vect_used_in_loop
              && STMT_VINFO_DEF_TYPE (stmt_info) != vect_induction_def)
@@ -337,12 +337,16 @@ vect_analyze_operations (loop_vec_info loop_vinfo)
                fprintf (vect_dump, "not vectorized: unsupported pattern.");
             return false;
            }
+
+         if (STMT_VINFO_RELEVANT_P (stmt_info))
+           need_to_vectorize = true;
        }
 
       for (si = bsi_start (bb); !bsi_end_p (si); bsi_next (&si))
        {
          tree stmt = bsi_stmt (si);
          stmt_vec_info stmt_info = vinfo_for_stmt (stmt);
+         enum vect_def_type relevance = STMT_VINFO_RELEVANT (stmt_info);
 
          if (vect_print_dump_info (REPORT_DETAILS))
            {
@@ -367,55 +371,57 @@ vect_analyze_operations (loop_vec_info loop_vinfo)
              continue;
            }
 
-          if (STMT_VINFO_RELEVANT_P (stmt_info))
-            {
-              gcc_assert (GIMPLE_STMT_P (stmt)
-                         || !VECTOR_MODE_P (TYPE_MODE (TREE_TYPE (stmt))));
-              gcc_assert (STMT_VINFO_VECTYPE (stmt_info));
-
-             ok = (vectorizable_type_promotion (stmt, NULL, NULL)
-                   || vectorizable_type_demotion (stmt, NULL, NULL)
-                   || vectorizable_conversion (stmt, NULL, NULL)
-                   || vectorizable_operation (stmt, NULL, NULL)
-                   || vectorizable_assignment (stmt, NULL, NULL)
-                   || vectorizable_load (stmt, NULL, NULL)
-                   || vectorizable_call (stmt, NULL, NULL)
-                   || vectorizable_store (stmt, NULL, NULL)
-                   || vectorizable_condition (stmt, NULL, NULL));
-
-             if (!ok)
-               {
-                 if (vect_print_dump_info (REPORT_UNVECTORIZED_LOOPS))
-                   {
-                     fprintf (vect_dump, 
-                              "not vectorized: relevant stmt not supported: ");
-                     print_generic_expr (vect_dump, stmt, TDF_SLIM);
-                   }
-                 return false;
-               }       
-             need_to_vectorize = true;
-            }
-
-         if (STMT_VINFO_LIVE_P (stmt_info))
+         switch (STMT_VINFO_DEF_TYPE (stmt_info))
            {
-             ok = vectorizable_reduction (stmt, NULL, NULL);
+           case vect_loop_def:
+             break;
+       
+           case vect_reduction_def:
+             gcc_assert (relevance == vect_unused_in_loop);
+             break;    
+
+           case vect_induction_def:
+           case vect_constant_def:
+           case vect_invariant_def:
+           case vect_unknown_def_type:
+           default:
+             gcc_unreachable ();       
+           }
 
-             if (ok)
-                need_to_vectorize = true;
-              else
-               ok = vectorizable_live_operation (stmt, NULL, NULL);
+         if (STMT_VINFO_RELEVANT_P (stmt_info))
+           {
+             gcc_assert (GIMPLE_STMT_P (stmt)
+                         || !VECTOR_MODE_P (TYPE_MODE (TREE_TYPE (stmt))));
+             gcc_assert (STMT_VINFO_VECTYPE (stmt_info));
+             need_to_vectorize = true;
+           }
 
-             if (!ok)
+         ok = (vectorizable_type_promotion (stmt, NULL, NULL)
+               || vectorizable_type_demotion (stmt, NULL, NULL)
+               || vectorizable_conversion (stmt, NULL, NULL)
+               || vectorizable_operation (stmt, NULL, NULL)
+               || vectorizable_assignment (stmt, NULL, NULL)
+               || vectorizable_load (stmt, NULL, NULL)
+               || vectorizable_call (stmt, NULL, NULL)
+               || vectorizable_store (stmt, NULL, NULL)
+               || vectorizable_condition (stmt, NULL, NULL)
+               || vectorizable_reduction (stmt, NULL, NULL));
+
+         /* Stmts that are (also) "live" (i.e. - that are used out of the loop)
+            need extra handling, except for vectorizable reductions.  */
+         if (STMT_VINFO_LIVE_P (stmt_info)
+             && STMT_VINFO_TYPE (stmt_info) != reduc_vec_info_type) 
+           ok |= vectorizable_live_operation (stmt, NULL, NULL);
+
+         if (!ok)
+           {
+             if (vect_print_dump_info (REPORT_UNVECTORIZED_LOOPS))
                {
-                 if (vect_print_dump_info (REPORT_UNVECTORIZED_LOOPS))
-                   {
-                     fprintf (vect_dump, 
-                              "not vectorized: live stmt not supported: ");
-                     print_generic_expr (vect_dump, stmt, TDF_SLIM);
-                   }
-                 return false;
+                 fprintf (vect_dump, "not vectorized: stmt not supported: ");
+                 print_generic_expr (vect_dump, stmt, TDF_SLIM);
                }
-           }
+             return false;
+           }   
        } /* stmts in bb */
     } /* bbs */
 
index 456138361d43f8b5e78334523c414cd4fa3834c1..32fe626180ce40345d6254d86cfc7f111c7251e4 100644 (file)
@@ -1816,6 +1816,20 @@ vectorizable_call (tree stmt, block_stmt_iterator *bsi, tree *vec_stmt)
   int ncopies, j, nargs;
   call_expr_arg_iterator iter;
 
+  if (!STMT_VINFO_RELEVANT_P (stmt_info))
+    return false;
+
+  if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_loop_def)
+    return false;
+
+  /* FORNOW: not yet supported.  */
+  if (STMT_VINFO_LIVE_P (stmt_info))
+    {
+      if (vect_print_dump_info (REPORT_DETAILS))
+        fprintf (vect_dump, "value used after loop.");
+      return false;
+    }
+
   /* Is STMT a vectorizable call?   */
   if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
     return false;
@@ -1994,7 +2008,8 @@ vectorizable_conversion (tree stmt, block_stmt_iterator * bsi,
   if (!STMT_VINFO_RELEVANT_P (stmt_info))
     return false;
 
-  gcc_assert (STMT_VINFO_DEF_TYPE (stmt_info) == vect_loop_def);
+  if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_loop_def)
+    return false;
 
   if (STMT_VINFO_LIVE_P (stmt_info))
     {
@@ -2134,12 +2149,21 @@ vectorizable_assignment (tree stmt, block_stmt_iterator *bsi, tree *vec_stmt)
   if (ncopies > 1)
     return false; /* FORNOW */
 
-  /* Is vectorizable assignment?  */
   if (!STMT_VINFO_RELEVANT_P (stmt_info))
     return false;
 
-  gcc_assert (STMT_VINFO_DEF_TYPE (stmt_info) == vect_loop_def);
+  if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_loop_def)
+    return false;
+
+  /* FORNOW: not yet supported.  */
+  if (STMT_VINFO_LIVE_P (stmt_info))
+    {
+      if (vect_print_dump_info (REPORT_DETAILS))
+        fprintf (vect_dump, "value used after loop.");
+      return false;
+    }
 
+  /* Is vectorizable assignment?  */
   if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
     return false;
 
@@ -2246,20 +2270,21 @@ vectorizable_operation (tree stmt, block_stmt_iterator *bsi, tree *vec_stmt)
 
   gcc_assert (ncopies >= 1);
 
-  /* Is STMT a vectorizable binary/unary operation?   */
   if (!STMT_VINFO_RELEVANT_P (stmt_info))
     return false;
 
-  gcc_assert (STMT_VINFO_DEF_TYPE (stmt_info) == vect_loop_def);
+  if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_loop_def)
+    return false;
 
+  /* FORNOW: not yet supported.  */
   if (STMT_VINFO_LIVE_P (stmt_info))
     {
-      /* FORNOW: not yet supported.  */
       if (vect_print_dump_info (REPORT_DETAILS))
         fprintf (vect_dump, "value used after loop.");
       return false;
     }
 
+  /* Is STMT a vectorizable binary/unary operation?   */
   if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
     return false;
 
@@ -2514,21 +2539,21 @@ vectorizable_type_demotion (tree stmt, block_stmt_iterator *bsi,
   optab optab;
   enum machine_mode vec_mode;
                                                                                 
-  /* Is STMT a vectorizable type-demotion operation?  */
-                                                                                
   if (!STMT_VINFO_RELEVANT_P (stmt_info))
     return false;
-                                                                                
-  gcc_assert (STMT_VINFO_DEF_TYPE (stmt_info) == vect_loop_def);
-                                                                                
+
+  if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_loop_def)
+    return false;
+
+  /* FORNOW: not yet supported.  */
   if (STMT_VINFO_LIVE_P (stmt_info))
     {
-      /* FORNOW: not yet supported.  */
       if (vect_print_dump_info (REPORT_DETAILS))
         fprintf (vect_dump, "value used after loop.");
       return false;
     }
                                                                                 
+  /* Is STMT a vectorizable type-demotion operation?  */
   if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
     return false;
                                                                                 
@@ -2723,21 +2748,21 @@ vectorizable_type_promotion (tree stmt, block_stmt_iterator *bsi,
   int j;
   tree vectype_in;
   
-  /* Is STMT a vectorizable type-promotion operation?  */
-
   if (!STMT_VINFO_RELEVANT_P (stmt_info))
     return false;
 
-  gcc_assert (STMT_VINFO_DEF_TYPE (stmt_info) == vect_loop_def);
+  if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_loop_def)
+    return false;
 
+  /* FORNOW: not yet supported.  */
   if (STMT_VINFO_LIVE_P (stmt_info))
     {
-      /* FORNOW: not yet supported.  */
       if (vect_print_dump_info (REPORT_DETAILS))
-       fprintf (vect_dump, "value used after loop.");
+        fprintf (vect_dump, "value used after loop.");
       return false;
     }
 
+  /* Is STMT a vectorizable type-promotion operation?  */
   if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
     return false;
 
@@ -3064,6 +3089,19 @@ vectorizable_store (tree stmt, block_stmt_iterator *bsi, tree *vec_stmt)
   VEC(tree,heap) *dr_chain = NULL, *oprnds = NULL, *result_chain = NULL;
   gcc_assert (ncopies >= 1);
 
+  if (!STMT_VINFO_RELEVANT_P (stmt_info))
+    return false;
+
+  if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_loop_def)
+    return false;
+
+  if (STMT_VINFO_LIVE_P (stmt_info))
+    {
+      if (vect_print_dump_info (REPORT_DETAILS))
+        fprintf (vect_dump, "value used after loop.");
+      return false;
+    }
+
   /* Is vectorizable store? */
 
   if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
@@ -3710,20 +3748,21 @@ vectorizable_load (tree stmt, block_stmt_iterator *bsi, tree *vec_stmt)
   bool strided_load = false;
   tree first_stmt;
 
-  /* Is vectorizable load? */
   if (!STMT_VINFO_RELEVANT_P (stmt_info))
     return false;
 
-  gcc_assert (STMT_VINFO_DEF_TYPE (stmt_info) == vect_loop_def);
+  if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_loop_def)
+    return false;
 
+  /* FORNOW: not yet supported.  */
   if (STMT_VINFO_LIVE_P (stmt_info))
     {
-      /* FORNOW: not yet supported.  */
       if (vect_print_dump_info (REPORT_DETAILS))
         fprintf (vect_dump, "value used after loop.");
       return false;
     }
 
+  /* Is vectorizable load? */
   if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
     return false;
 
@@ -4010,7 +4049,9 @@ vectorizable_live_operation (tree stmt,
   tree def, def_stmt;
   enum vect_def_type dt; 
 
-  if (!STMT_VINFO_LIVE_P (stmt_info))
+  gcc_assert (STMT_VINFO_LIVE_P (stmt_info));
+
+  if (STMT_VINFO_DEF_TYPE (stmt_info) == vect_reduction_def)
     return false;
 
   if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
@@ -4123,16 +4164,18 @@ vectorizable_condition (tree stmt, block_stmt_iterator *bsi, tree *vec_stmt)
   if (!STMT_VINFO_RELEVANT_P (stmt_info))
     return false;
 
-  gcc_assert (STMT_VINFO_DEF_TYPE (stmt_info) == vect_loop_def);
+  if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_loop_def)
+    return false;
 
+  /* FORNOW: not yet supported.  */
   if (STMT_VINFO_LIVE_P (stmt_info))
     {
-      /* FORNOW: not yet supported.  */
       if (vect_print_dump_info (REPORT_DETAILS))
         fprintf (vect_dump, "value used after loop.");
       return false;
     }
 
+  /* Is vectorizable conditional operation?  */
   if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
     return false;
 
@@ -4225,110 +4268,103 @@ vect_transform_stmt (tree stmt, block_stmt_iterator *bsi, bool *strided_store)
   tree orig_stmt_in_pattern;
   bool done;
 
-  if (STMT_VINFO_RELEVANT_P (stmt_info))
+  switch (STMT_VINFO_TYPE (stmt_info))
     {
-      switch (STMT_VINFO_TYPE (stmt_info))
-      {
-      case type_demotion_vec_info_type:
-        done = vectorizable_type_demotion (stmt, bsi, &vec_stmt);
-        gcc_assert (done);
-        break;
+    case type_demotion_vec_info_type:
+      done = vectorizable_type_demotion (stmt, bsi, &vec_stmt);
+      gcc_assert (done);
+      break;
                                                                                 
-      case type_promotion_vec_info_type:
-       done = vectorizable_type_promotion (stmt, bsi, &vec_stmt);
-       gcc_assert (done);
-       break;
-
-      case type_conversion_vec_info_type:
-       done = vectorizable_conversion (stmt, bsi, &vec_stmt);
-       gcc_assert (done);
-       break;
-
-      case op_vec_info_type:
-       done = vectorizable_operation (stmt, bsi, &vec_stmt);
-       gcc_assert (done);
-       break;
-
-      case assignment_vec_info_type:
-       done = vectorizable_assignment (stmt, bsi, &vec_stmt);
-       gcc_assert (done);
-       break;
-
-      case load_vec_info_type:
-       done = vectorizable_load (stmt, bsi, &vec_stmt);
-       gcc_assert (done);
-       break;
-
-      case store_vec_info_type:
-       done = vectorizable_store (stmt, bsi, &vec_stmt);
-       gcc_assert (done);
-       if (DR_GROUP_FIRST_DR (stmt_info))
-         {
-           /* In case of interleaving, the whole chain is vectorized when the
-              last store in the chain is reached. Store stmts before the last
-              one are skipped, and there vec_stmt_info shouldn't be freed
-              meanwhile.  */
-           *strided_store = true;
-           if (STMT_VINFO_VEC_STMT (stmt_info))
-             is_store = true;
+    case type_promotion_vec_info_type:
+      done = vectorizable_type_promotion (stmt, bsi, &vec_stmt);
+      gcc_assert (done);
+      break;
+
+    case type_conversion_vec_info_type:
+      done = vectorizable_conversion (stmt, bsi, &vec_stmt);
+      gcc_assert (done);
+      break;
+
+    case op_vec_info_type:
+      done = vectorizable_operation (stmt, bsi, &vec_stmt);
+      gcc_assert (done);
+      break;
+
+    case assignment_vec_info_type:
+      done = vectorizable_assignment (stmt, bsi, &vec_stmt);
+      gcc_assert (done);
+      break;
+
+    case load_vec_info_type:
+      done = vectorizable_load (stmt, bsi, &vec_stmt);
+      gcc_assert (done);
+      break;
+
+    case store_vec_info_type:
+      done = vectorizable_store (stmt, bsi, &vec_stmt);
+      gcc_assert (done);
+      if (DR_GROUP_FIRST_DR (stmt_info))
+       {
+         /* In case of interleaving, the whole chain is vectorized when the
+            last store in the chain is reached. Store stmts before the last
+            one are skipped, and there vec_stmt_info shouldn't be freed
+            meanwhile.  */
+         *strided_store = true;
+         if (STMT_VINFO_VEC_STMT (stmt_info))
+           is_store = true;
          }
-       else
-         is_store = true;
-       break;
+      else
+       is_store = true;
+      break;
 
-      case condition_vec_info_type:
-       done = vectorizable_condition (stmt, bsi, &vec_stmt);
-       gcc_assert (done);
-       break;
+    case condition_vec_info_type:
+      done = vectorizable_condition (stmt, bsi, &vec_stmt);
+      gcc_assert (done);
+      break;
 
-      case call_vec_info_type:
-       done = vectorizable_call (stmt, bsi, &vec_stmt);
-       break;
+    case call_vec_info_type:
+      done = vectorizable_call (stmt, bsi, &vec_stmt);
+      break;
 
-      default:
-       if (vect_print_dump_info (REPORT_DETAILS))
-         fprintf (vect_dump, "stmt not supported.");
-       gcc_unreachable ();
-      }
+    case reduc_vec_info_type:
+      done = vectorizable_reduction (stmt, bsi, &vec_stmt);
+      gcc_assert (done);
+      break;
 
-      gcc_assert (vec_stmt || *strided_store);
-      if (vec_stmt)
+    default:
+      if (!STMT_VINFO_LIVE_P (stmt_info))
        {
-         STMT_VINFO_VEC_STMT (stmt_info) = vec_stmt;
-         orig_stmt_in_pattern = STMT_VINFO_RELATED_STMT (stmt_info);
-         if (orig_stmt_in_pattern)
-           {
-             stmt_vec_info stmt_vinfo = vinfo_for_stmt (orig_stmt_in_pattern);
-             if (STMT_VINFO_IN_PATTERN_P (stmt_vinfo))
-               {
-                 gcc_assert (STMT_VINFO_RELATED_STMT (stmt_vinfo) == stmt);
-                 
-                 /* STMT was inserted by the vectorizer to replace a 
-                    computation idiom.  ORIG_STMT_IN_PATTERN is a stmt in the 
-                    original sequence that computed this idiom.  We need to 
-                    record a pointer to VEC_STMT in the stmt_info of 
-                    ORIG_STMT_IN_PATTERN.  See more details in the 
-                    documentation of vect_pattern_recog.  */
-
-                 STMT_VINFO_VEC_STMT (stmt_vinfo) = vec_stmt;
-               }
-           }
+         if (vect_print_dump_info (REPORT_DETAILS))
+           fprintf (vect_dump, "stmt not supported.");
+         gcc_unreachable ();
        }
     }
 
-  if (STMT_VINFO_LIVE_P (stmt_info))
+  if (STMT_VINFO_LIVE_P (stmt_info)
+      && STMT_VINFO_TYPE (stmt_info) != reduc_vec_info_type)
     {
-      switch (STMT_VINFO_TYPE (stmt_info))
-      {
-      case reduc_vec_info_type:
-        done = vectorizable_reduction (stmt, bsi, &vec_stmt);
-        gcc_assert (done);
-        break;
-
-      default:
-        done = vectorizable_live_operation (stmt, bsi, &vec_stmt);
-        gcc_assert (done);
-      }
+      done = vectorizable_live_operation (stmt, bsi, &vec_stmt);
+      gcc_assert (done);
+    }
+
+  if (vec_stmt)
+    {
+      STMT_VINFO_VEC_STMT (stmt_info) = vec_stmt;
+      orig_stmt_in_pattern = STMT_VINFO_RELATED_STMT (stmt_info);
+      if (orig_stmt_in_pattern)
+       {
+         stmt_vec_info stmt_vinfo = vinfo_for_stmt (orig_stmt_in_pattern);
+         /* STMT was inserted by the vectorizer to replace a computation idiom.
+            ORIG_STMT_IN_PATTERN is a stmt in the original sequence that 
+            computed this idiom.  We need to record a pointer to VEC_STMT in 
+            the stmt_info of ORIG_STMT_IN_PATTERN.  See more details in the 
+            documentation of vect_pattern_recog.  */
+         if (STMT_VINFO_IN_PATTERN_P (stmt_vinfo))
+           {
+             gcc_assert (STMT_VINFO_RELATED_STMT (stmt_vinfo) == stmt);
+             STMT_VINFO_VEC_STMT (stmt_vinfo) = vec_stmt;
+           }
+       }
     }
 
   return is_store;