[05/11] Add a vect_stmt_to_vectorize helper function
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 1 Aug 2018 15:14:42 +0000 (15:14 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Wed, 1 Aug 2018 15:14:42 +0000 (15:14 +0000)
This patch adds a helper that does the opposite of vect_orig_stmt:
go from the original scalar statement to the statement that should
actually be vectorised.

The use in the last two hunks of vectorizable_reduction are because
reduc_stmt_info (first hunk) and stmt_info (second hunk) are already
pattern statements if appropriate.

2018-08-01  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
* tree-vectorizer.h (vect_stmt_to_vectorize): New function.
* tree-vect-loop.c (vect_update_vf_for_slp): Use it.
(vectorizable_reduction): Likewise.
* tree-vect-slp.c (vect_analyze_slp_instance): Likewise.
(vect_detect_hybrid_slp_stmts): Likewise.
* tree-vect-stmts.c (vect_is_simple_use): Likewise.

From-SVN: r263219

gcc/ChangeLog
gcc/tree-vect-loop.c
gcc/tree-vect-slp.c
gcc/tree-vect-stmts.c
gcc/tree-vectorizer.h

index a0552f8c60d8f3ac7c2a0424a465441d0a2e6ecc..227d0457315a0345da107d06f485f8f8fa11f604 100644 (file)
@@ -1,3 +1,12 @@
+2018-08-01  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * tree-vectorizer.h (vect_stmt_to_vectorize): New function.
+       * tree-vect-loop.c (vect_update_vf_for_slp): Use it.
+       (vectorizable_reduction): Likewise.
+       * tree-vect-slp.c (vect_analyze_slp_instance): Likewise.
+       (vect_detect_hybrid_slp_stmts): Likewise.
+       * tree-vect-stmts.c (vect_is_simple_use): Likewise.
+
 2018-08-01  Aldy Hernandez  <aldyh@redhat.com>
 
        * tree-vrp (zero_nonzero_bits_from_bounds): Rename to...
index b5d1671aa6b1c60256cbd471a91b3cc6a9ab7fa9..f4ce5b6033b4330f1eb4f54bf34c327267d50d7f 100644 (file)
@@ -1424,9 +1424,7 @@ vect_update_vf_for_slp (loop_vec_info loop_vinfo)
           gsi_next (&si))
        {
          stmt_vec_info stmt_info = loop_vinfo->lookup_stmt (gsi_stmt (si));
-         if (STMT_VINFO_IN_PATTERN_P (stmt_info)
-             && STMT_VINFO_RELATED_STMT (stmt_info))
-           stmt_info = STMT_VINFO_RELATED_STMT (stmt_info);
+         stmt_info = vect_stmt_to_vectorize (stmt_info);
          if ((STMT_VINFO_RELEVANT_P (stmt_info)
               || VECTORIZABLE_CYCLE_DEF (STMT_VINFO_DEF_TYPE (stmt_info)))
              && !PURE_SLP_STMT (stmt_info))
@@ -6111,8 +6109,7 @@ vectorizable_reduction (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
        return true;
 
       stmt_vec_info reduc_stmt_info = STMT_VINFO_REDUC_DEF (stmt_info);
-      if (STMT_VINFO_IN_PATTERN_P (reduc_stmt_info))
-       reduc_stmt_info = STMT_VINFO_RELATED_STMT (reduc_stmt_info);
+      reduc_stmt_info = vect_stmt_to_vectorize (reduc_stmt_info);
 
       if (STMT_VINFO_VEC_REDUCTION_TYPE (reduc_stmt_info)
          == EXTRACT_LAST_REDUCTION)
@@ -6145,8 +6142,7 @@ vectorizable_reduction (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
       if (ncopies > 1
          && STMT_VINFO_RELEVANT (reduc_stmt_info) <= vect_used_only_live
          && (use_stmt_info = loop_vinfo->lookup_single_use (phi_result))
-         && (use_stmt_info == reduc_stmt_info
-             || STMT_VINFO_RELATED_STMT (use_stmt_info) == reduc_stmt_info))
+         && vect_stmt_to_vectorize (use_stmt_info) == reduc_stmt_info)
        single_defuse_cycle = true;
 
       /* Create the destination vector  */
@@ -6915,8 +6911,7 @@ vectorizable_reduction (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
   if (ncopies > 1
       && (STMT_VINFO_RELEVANT (stmt_info) <= vect_used_only_live)
       && (use_stmt_info = loop_vinfo->lookup_single_use (reduc_phi_result))
-      && (use_stmt_info == stmt_info
-         || STMT_VINFO_RELATED_STMT (use_stmt_info) == stmt_info))
+      && vect_stmt_to_vectorize (use_stmt_info) == stmt_info)
     {
       single_defuse_cycle = true;
       epilog_copies = 1;
index f9a83dd77bae9d9c9b0ef30483bab5b44c84aa76..d0f6da4a6acf21e70b81238cf98ecf327d23c30e 100644 (file)
@@ -1969,11 +1969,7 @@ vect_analyze_slp_instance (vec_info *vinfo,
       /* Collect the stores and store them in SLP_TREE_SCALAR_STMTS.  */
       while (next_info)
         {
-         if (STMT_VINFO_IN_PATTERN_P (next_info)
-             && STMT_VINFO_RELATED_STMT (next_info))
-           scalar_stmts.safe_push (STMT_VINFO_RELATED_STMT (next_info));
-         else
-           scalar_stmts.safe_push (next_info);
+         scalar_stmts.safe_push (vect_stmt_to_vectorize (next_info));
          next_info = DR_GROUP_NEXT_ELEMENT (next_info);
         }
     }
@@ -1983,11 +1979,7 @@ vect_analyze_slp_instance (vec_info *vinfo,
         SLP_TREE_SCALAR_STMTS.  */
       while (next_info)
         {
-         if (STMT_VINFO_IN_PATTERN_P (next_info)
-             && STMT_VINFO_RELATED_STMT (next_info))
-           scalar_stmts.safe_push (STMT_VINFO_RELATED_STMT (next_info));
-         else
-           scalar_stmts.safe_push (next_info);
+         scalar_stmts.safe_push (vect_stmt_to_vectorize (next_info));
          next_info = REDUC_GROUP_NEXT_ELEMENT (next_info);
         }
       /* Mark the first element of the reduction chain as reduction to properly
@@ -2325,9 +2317,7 @@ vect_detect_hybrid_slp_stmts (slp_tree node, unsigned i, slp_vect_type stype)
            use_vinfo = loop_vinfo->lookup_stmt (use_stmt);
            if (!use_vinfo)
              continue;
-           if (STMT_VINFO_IN_PATTERN_P (use_vinfo)
-               && STMT_VINFO_RELATED_STMT (use_vinfo))
-             use_vinfo = STMT_VINFO_RELATED_STMT (use_vinfo);
+           use_vinfo = vect_stmt_to_vectorize (use_vinfo);
            if (!STMT_SLP_TYPE (use_vinfo)
                && (STMT_VINFO_RELEVANT (use_vinfo)
                    || VECTORIZABLE_CYCLE_DEF (STMT_VINFO_DEF_TYPE (use_vinfo)))
index f3a2d80f98cf3c8542d24a0d58a47ec821bd82db..9d51c10bcbc8483cb49913ced06cfcd9729541a0 100644 (file)
@@ -10031,11 +10031,8 @@ vect_is_simple_use (tree operand, vec_info *vinfo, enum vect_def_type *dt,
        *dt = vect_external_def;
       else
        {
-         if (STMT_VINFO_IN_PATTERN_P (stmt_vinfo))
-           {
-             stmt_vinfo = STMT_VINFO_RELATED_STMT (stmt_vinfo);
-             def_stmt = stmt_vinfo->stmt;
-           }
+         stmt_vinfo = vect_stmt_to_vectorize (stmt_vinfo);
+         def_stmt = stmt_vinfo->stmt;
          switch (gimple_code (def_stmt))
            {
            case GIMPLE_PHI:
index a8403d5299ca9841d8b7816de4e90034c144b9b5..5de2be9a69c833052c3037a52bb0a693ddf8d178 100644 (file)
@@ -1131,6 +1131,17 @@ vect_orig_stmt (stmt_vec_info stmt_info)
   return stmt_info;
 }
 
+/* If STMT_INFO has been replaced by a pattern statement, return the
+   replacement statement, otherwise return STMT_INFO itself.  */
+
+inline stmt_vec_info
+vect_stmt_to_vectorize (stmt_vec_info stmt_info)
+{
+  if (STMT_VINFO_IN_PATTERN_P (stmt_info))
+    return STMT_VINFO_RELATED_STMT (stmt_info);
+  return stmt_info;
+}
+
 /* Return true if BB is a loop header.  */
 
 static inline bool