[7/n] PR85694: Add a vect_pattern_detected helper
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 20 Jun 2018 08:11:46 +0000 (08:11 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Wed, 20 Jun 2018 08:11:46 +0000 (08:11 +0000)
This message is a long write-up for a patch that simply adds a common
routine for printing the "vector_foo_pattern: detected:" messages.

The reason for doing this is that some routines check for target support
themselves and some leave it to vect_pattern_recog_1.  Those that leave
it to vect_pattern_recog_1 currently print these "detected:" messages if
the statements have the right form, even if the pattern is eventually
discarded.  IMO that's useful, and a lot of existing scan tests rely on it.

However, a later patch makes patterns do their own testing, and stops
them creating pattern statements until the tests have passed.  This means
(a) they need to print the "detected:" message earlier and (b) the pattern
statement won't be around to print.

The patch therefore makes all routines print the original statement
rather than the pattern one.  That information isn't obvious otherwise,
whereas vect_pattern_recog_1 already prints the pattern statement
in the case of a successful match.  This also avoids the previous
situation in which a routine could print "detected:" and then
silently bail out before saying what had been detected.

2018-06-20  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
* tree-vect-patterns.c (vect_pattern_detected): New function.
(vect_recog_dot_prod_patternm, vect_recog_sad_pattern)
(vect_recog_widen_mult_pattern, vect_recog_widen_sum_pattern)
(vect_recog_over_widening_pattern, vect_recog_widen_shift_pattern
(vect_recog_rotate_pattern, vect_recog_vector_vector_shift_pattern)
(vect_recog_mult_pattern, vect_recog_divmod_pattern)
(vect_recog_mixed_size_cond_pattern, vect_recog_bool_pattern)
(vect_recog_mask_conversion_pattern)
(vect_try_gather_scatter_pattern): Likewise.

From-SVN: r261790

gcc/ChangeLog
gcc/tree-vect-patterns.c

index 6ad807c337e2b8618db3a7443469e5161ed00c36..384c6ad49f63ccbb192990a2257899b655ea52c6 100644 (file)
@@ -1,3 +1,15 @@
+2018-06-20  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * tree-vect-patterns.c (vect_pattern_detected): New function.
+       (vect_recog_dot_prod_patternm, vect_recog_sad_pattern)
+       (vect_recog_widen_mult_pattern, vect_recog_widen_sum_pattern)
+       (vect_recog_over_widening_pattern, vect_recog_widen_shift_pattern
+       (vect_recog_rotate_pattern, vect_recog_vector_vector_shift_pattern)
+       (vect_recog_mult_pattern, vect_recog_divmod_pattern)
+       (vect_recog_mixed_size_cond_pattern, vect_recog_bool_pattern)
+       (vect_recog_mask_conversion_pattern)
+       (vect_try_gather_scatter_pattern): Likewise.
+
 2018-06-20  Richard Sandiford  <richard.sandiford@arm.com>
 
        * tree-vect-patterns.c (vect_get_internal_def): New function.
index 71b31aca21c7e2d0d10c0a8fbb9f6c26424d6620..3d7f866fe375364e41e866fec957ee3b2b821e76 100644 (file)
@@ -107,6 +107,19 @@ static vect_recog_func vect_vect_recog_func_ptrs[NUM_PATTERNS] = {
       {        vect_recog_mask_conversion_pattern, "mask_conversion" }
 };
 
+/* Report that we've found an instance of pattern PATTERN in
+   statement STMT.  */
+
+static void
+vect_pattern_detected (const char *name, gimple *stmt)
+{
+  if (dump_enabled_p ())
+    {
+      dump_printf_loc (MSG_NOTE, vect_location, "%s: detected: ", name);
+      dump_gimple_stmt (MSG_NOTE, TDF_SLIM, stmt, 0);
+    }
+}
+
 static inline void
 append_pattern_def_seq (stmt_vec_info stmt_info, gimple *stmt)
 {
@@ -432,22 +445,16 @@ vect_recog_dot_prod_pattern (vec<gimple *> *stmts, tree *type_in,
        return NULL;
     }
 
+  vect_pattern_detected ("vect_recog_dot_prod_pattern", last_stmt);
+
   half_type = TREE_TYPE (oprnd00);
   *type_in = half_type;
   *type_out = type;
 
-  /* Pattern detected. Create a stmt to be used to replace the pattern: */
   var = vect_recog_temp_ssa_var (type, NULL);
   pattern_stmt = gimple_build_assign (var, DOT_PROD_EXPR,
                                      oprnd00, oprnd01, oprnd1);
 
-  if (dump_enabled_p ())
-    {
-      dump_printf_loc (MSG_NOTE, vect_location,
-                       "vect_recog_dot_prod_pattern: detected: ");
-      dump_gimple_stmt (MSG_NOTE, TDF_SLIM, pattern_stmt, 0);
-    }
-
   return pattern_stmt;
 }
 
@@ -632,21 +639,15 @@ vect_recog_sad_pattern (vec<gimple *> *stmts, tree *type_in,
       || TYPE_PRECISION (sum_type) < TYPE_PRECISION (half_type0) * 2)
     return NULL;
 
+  vect_pattern_detected ("vect_recog_sad_pattern", last_stmt);
+
   *type_in = TREE_TYPE (sad_oprnd0);
   *type_out = sum_type;
 
-  /* Pattern detected. Create a stmt to be used to replace the pattern: */
   tree var = vect_recog_temp_ssa_var (sum_type, NULL);
   gimple *pattern_stmt = gimple_build_assign (var, SAD_EXPR, sad_oprnd0,
                                              sad_oprnd1, plus_oprnd1);
 
-  if (dump_enabled_p ())
-    {
-      dump_printf_loc (MSG_NOTE, vect_location,
-                       "vect_recog_sad_pattern: detected: ");
-      dump_gimple_stmt (MSG_NOTE, TDF_SLIM, pattern_stmt, 0);
-    }
-
   return pattern_stmt;
 }
 
@@ -919,9 +920,7 @@ vect_recog_widen_mult_pattern (vec<gimple *> *stmts,
               TYPE_UNSIGNED (type));
 
   /* Pattern detected.  */
-  if (dump_enabled_p ())
-    dump_printf_loc (MSG_NOTE, vect_location,
-                     "vect_recog_widen_mult_pattern: detected:\n");
+  vect_pattern_detected ("vect_recog_widen_mult_pattern", last_stmt);
 
   /* Check target support  */
   vectype = get_vectype_for_scalar_type (half_type0);
@@ -970,9 +969,6 @@ vect_recog_widen_mult_pattern (vec<gimple *> *stmts,
                                          gimple_assign_lhs (pattern_stmt));
     }
 
-  if (dump_enabled_p ())
-    dump_gimple_stmt_loc (MSG_NOTE, vect_location, TDF_SLIM, pattern_stmt, 0);
-
   stmts->safe_push (last_stmt);
   return pattern_stmt;
 }
@@ -1230,20 +1226,15 @@ vect_recog_widen_sum_pattern (vec<gimple *> *stmts, tree *type_in,
      return NULL;
 
   oprnd0 = gimple_assign_rhs1 (stmt);
+
+  vect_pattern_detected ("vect_recog_widen_sum_pattern", last_stmt);
+
   *type_in = half_type;
   *type_out = type;
 
-  /* Pattern detected. Create a stmt to be used to replace the pattern: */
   var = vect_recog_temp_ssa_var (type, NULL);
   pattern_stmt = gimple_build_assign (var, WIDEN_SUM_EXPR, oprnd0, oprnd1);
 
-  if (dump_enabled_p ())
-    {
-      dump_printf_loc (MSG_NOTE, vect_location,
-                       "vect_recog_widen_sum_pattern: detected: ");
-      dump_gimple_stmt (MSG_NOTE, TDF_SLIM, pattern_stmt, 0);
-    }
-
   return pattern_stmt;
 }
 
@@ -1603,12 +1594,7 @@ vect_recog_over_widening_pattern (vec<gimple *> *stmts,
     return NULL;
 
   /* Pattern detected.  */
-  if (dump_enabled_p ())
-    {
-      dump_printf_loc (MSG_NOTE, vect_location,
-                       "vect_recog_over_widening_pattern: detected: ");
-      dump_gimple_stmt (MSG_NOTE, TDF_SLIM, pattern_stmt, 0);
-    }
+  vect_pattern_detected ("vect_recog_over_widening_pattern", stmts->last ());
 
   return pattern_stmt;
 }
@@ -1740,9 +1726,7 @@ vect_recog_widen_shift_pattern (vec<gimple *> *stmts,
     return NULL;
 
   /* Pattern detected.  */
-  if (dump_enabled_p ())
-    dump_printf_loc (MSG_NOTE, vect_location,
-                     "vect_recog_widen_shift_pattern: detected:\n");
+  vect_pattern_detected ("vect_recog_widen_shift_pattern", last_stmt);
 
   /* Check target support.  */
   vectype = get_vectype_for_scalar_type (half_type0);
@@ -1773,9 +1757,6 @@ vect_recog_widen_shift_pattern (vec<gimple *> *stmts,
       STMT_VINFO_VECTYPE (new_stmt_info) = vectype;
     }
 
-  if (dump_enabled_p ())
-    dump_gimple_stmt_loc (MSG_NOTE, vect_location, TDF_SLIM, pattern_stmt, 0);
-
   stmts->safe_push (last_stmt);
   return pattern_stmt;
 }
@@ -2010,17 +1991,12 @@ vect_recog_rotate_pattern (vec<gimple *> *stmts, tree *type_in, tree *type_out)
   append_pattern_def_seq (stmt_vinfo, def_stmt);
 
   /* Pattern detected.  */
-  if (dump_enabled_p ())
-    dump_printf_loc (MSG_NOTE, vect_location,
-                    "vect_recog_rotate_pattern: detected:\n");
+  vect_pattern_detected ("vect_recog_rotate_pattern", last_stmt);
 
   /* Pattern supported.  Create a stmt to be used to replace the pattern.  */
   var = vect_recog_temp_ssa_var (type, NULL);
   pattern_stmt = gimple_build_assign (var, BIT_IOR_EXPR, var1, var2);
 
-  if (dump_enabled_p ())
-    dump_gimple_stmt_loc (MSG_NOTE, vect_location, TDF_SLIM, pattern_stmt, 0);
-
   stmts->safe_push (last_stmt);
   return pattern_stmt;
 }
@@ -2153,17 +2129,12 @@ vect_recog_vector_vector_shift_pattern (vec<gimple *> *stmts,
     }
 
   /* Pattern detected.  */
-  if (dump_enabled_p ())
-    dump_printf_loc (MSG_NOTE, vect_location,
-                     "vect_recog_vector_vector_shift_pattern: detected:\n");
+  vect_pattern_detected ("vect_recog_vector_vector_shift_pattern", last_stmt);
 
   /* Pattern supported.  Create a stmt to be used to replace the pattern.  */
   var = vect_recog_temp_ssa_var (TREE_TYPE (oprnd0), NULL);
   pattern_stmt = gimple_build_assign (var, rhs_code, oprnd0, def);
 
-  if (dump_enabled_p ())
-    dump_gimple_stmt_loc (MSG_NOTE, vect_location, TDF_SLIM, pattern_stmt, 0);
-
   stmts->safe_push (last_stmt);
   return pattern_stmt;
 }
@@ -2530,13 +2501,7 @@ vect_recog_mult_pattern (vec<gimple *> *stmts,
     return NULL;
 
   /* Pattern detected.  */
-  if (dump_enabled_p ())
-    dump_printf_loc (MSG_NOTE, vect_location,
-                    "vect_recog_mult_pattern: detected:\n");
-
-  if (dump_enabled_p ())
-    dump_gimple_stmt_loc (MSG_NOTE, vect_location, TDF_SLIM,
-                         pattern_stmt,0);
+  vect_pattern_detected ("vect_recog_mult_pattern", last_stmt);
 
   stmts->safe_push (last_stmt);
   *type_in = vectype;
@@ -2652,9 +2617,7 @@ vect_recog_divmod_pattern (vec<gimple *> *stmts,
        return NULL;
 
       /* Pattern detected.  */
-      if (dump_enabled_p ())
-        dump_printf_loc (MSG_NOTE, vect_location,
-                         "vect_recog_divmod_pattern: detected:\n");
+      vect_pattern_detected ("vect_recog_divmod_pattern", last_stmt);
 
       cond = build2 (LT_EXPR, boolean_type_node, oprnd0,
                     build_int_cst (itype, 0));
@@ -2738,10 +2701,6 @@ vect_recog_divmod_pattern (vec<gimple *> *stmts,
                                   signmask);
        }
 
-      if (dump_enabled_p ())
-       dump_gimple_stmt_loc (MSG_NOTE, vect_location, TDF_SLIM, pattern_stmt,
-                              0);
-
       stmts->safe_push (last_stmt);
 
       *type_in = vectype;
@@ -2992,12 +2951,7 @@ vect_recog_divmod_pattern (vec<gimple *> *stmts,
     }
 
   /* Pattern detected.  */
-  if (dump_enabled_p ())
-    {
-      dump_printf_loc (MSG_NOTE, vect_location,
-                       "vect_recog_divmod_pattern: detected: ");
-      dump_gimple_stmt (MSG_NOTE, TDF_SLIM, pattern_stmt, 0);
-    }
+  vect_pattern_detected ("vect_recog_divmod_pattern", last_stmt);
 
   stmts->safe_push (last_stmt);
 
@@ -3157,9 +3111,7 @@ vect_recog_mixed_size_cond_pattern (vec<gimple *> *stmts, tree *type_in,
   *type_in = vecitype;
   *type_out = vectype;
 
-  if (dump_enabled_p ())
-    dump_printf_loc (MSG_NOTE, vect_location,
-                     "vect_recog_mixed_size_cond_pattern: detected:\n");
+  vect_pattern_detected ("vect_recog_mixed_size_cond_pattern", last_stmt);
 
   return pattern_stmt;
 }
@@ -3729,9 +3681,7 @@ vect_recog_bool_pattern (vec<gimple *> *stmts, tree *type_in,
       *type_out = vectype;
       *type_in = vectype;
       stmts->safe_push (last_stmt);
-      if (dump_enabled_p ())
-       dump_printf_loc (MSG_NOTE, vect_location,
-                         "vect_recog_bool_pattern: detected:\n");
+      vect_pattern_detected ("vect_recog_bool_pattern", last_stmt);
 
       return pattern_stmt;
     }
@@ -3770,9 +3720,7 @@ vect_recog_bool_pattern (vec<gimple *> *stmts, tree *type_in,
       *type_out = vectype;
       *type_in = vectype;
       stmts->safe_push (last_stmt);
-      if (dump_enabled_p ())
-       dump_printf_loc (MSG_NOTE, vect_location,
-                         "vect_recog_bool_pattern: detected:\n");
+      vect_pattern_detected ("vect_recog_bool_pattern", last_stmt);
 
       return pattern_stmt;
     }
@@ -3829,9 +3777,8 @@ vect_recog_bool_pattern (vec<gimple *> *stmts, tree *type_in,
       *type_out = vectype;
       *type_in = vectype;
       stmts->safe_push (last_stmt);
-      if (dump_enabled_p ())
-       dump_printf_loc (MSG_NOTE, vect_location,
-                         "vect_recog_bool_pattern: detected:\n");
+      vect_pattern_detected ("vect_recog_bool_pattern", last_stmt);
+
       return pattern_stmt;
     }
   else
@@ -3966,9 +3913,7 @@ vect_recog_mask_conversion_pattern (vec<gimple *> *stmts, tree *type_in,
       *type_out = vectype1;
       *type_in = vectype1;
       stmts->safe_push (last_stmt);
-      if (dump_enabled_p ())
-       dump_printf_loc (MSG_NOTE, vect_location,
-                         "vect_recog_mask_conversion_pattern: detected:\n");
+      vect_pattern_detected ("vect_recog_mask_conversion_pattern", last_stmt);
 
       return pattern_stmt;
     }
@@ -4092,9 +4037,7 @@ vect_recog_mask_conversion_pattern (vec<gimple *> *stmts, tree *type_in,
       *type_out = vectype1;
       *type_in = vectype1;
       stmts->safe_push (last_stmt);
-      if (dump_enabled_p ())
-       dump_printf_loc (MSG_NOTE, vect_location,
-                         "vect_recog_mask_conversion_pattern: detected:\n");
+      vect_pattern_detected ("vect_recog_mask_conversion_pattern", last_stmt);
 
       return pattern_stmt;
     }
@@ -4140,9 +4083,7 @@ vect_recog_mask_conversion_pattern (vec<gimple *> *stmts, tree *type_in,
   *type_out = vectype1;
   *type_in = vectype1;
   stmts->safe_push (last_stmt);
-  if (dump_enabled_p ())
-    dump_printf_loc (MSG_NOTE, vect_location,
-                    "vect_recog_mask_conversion_pattern: detected:\n");
+  vect_pattern_detected ("vect_recog_mask_conversion_pattern", last_stmt);
 
   return pattern_stmt;
 }
@@ -4324,10 +4265,7 @@ vect_try_gather_scatter_pattern (gimple *stmt, stmt_vec_info last_stmt_info,
   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
   *type_out = vectype;
   *type_in = vectype;
-
-  if (dump_enabled_p ())
-    dump_printf_loc (MSG_NOTE, vect_location,
-                    "gather/scatter pattern detected:\n");
+  vect_pattern_detected ("gather/scatter pattern", stmt);
 
   return pattern_stmt;
 }