Don't assign a cost to vectorizable_assignment
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 13 Nov 2019 09:03:07 +0000 (09:03 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Wed, 13 Nov 2019 09:03:07 +0000 (09:03 +0000)
vectorizable_assignment handles true SSA-to-SSA copies (which hopefully
we don't see in practice) and no-op conversions that are required
to maintain correct gimple, such as changes between signed and
unsigned types.  These cases shouldn't generate any code and so
shouldn't count against either the scalar or vector costs.

Later patches test this, but it seemed worth splitting out.

2019-11-13  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
* tree-vectorizer.h (vect_nop_conversion_p): Declare.
* tree-vect-stmts.c (vect_nop_conversion_p): New function.
(vectorizable_assignment): Don't add a cost for nop conversions.
* tree-vect-loop.c (vect_compute_single_scalar_iteration_cost):
Likewise.
* tree-vect-slp.c (vect_bb_slp_scalar_cost): Likewise.

From-SVN: r278122

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

index cb34395694785b2a24dca5456e701b85e6eb6e3b..9054178018eabae9142ae1473a5cff098c590c1d 100644 (file)
@@ -1,3 +1,12 @@
+2019-11-13  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * tree-vectorizer.h (vect_nop_conversion_p): Declare.
+       * tree-vect-stmts.c (vect_nop_conversion_p): New function.
+       (vectorizable_assignment): Don't add a cost for nop conversions.
+       * tree-vect-loop.c (vect_compute_single_scalar_iteration_cost):
+       Likewise.
+       * tree-vect-slp.c (vect_bb_slp_scalar_cost): Likewise.
+
 2019-11-13  Richard Sandiford  <richard.sandiford@arm.com>
 
        * tree-vect-stmts.c (vect_model_promotion_demotion_cost): Take the
index d9f413430dc1e41b34e0c9ff68b42763ede575e9..75ec9e67a5c787b1fc3634254bea2144cc4869ea 100644 (file)
@@ -1125,7 +1125,9 @@ vect_compute_single_scalar_iteration_cost (loop_vec_info loop_vinfo)
              else
                kind = scalar_store;
             }
-          else
+         else if (vect_nop_conversion_p (stmt_info))
+           continue;
+         else
             kind = scalar_stmt;
 
          record_stmt_cost (&LOOP_VINFO_SCALAR_ITERATION_COST (loop_vinfo),
index 4bc0cc77de4f4eeaf1835c6a804bf8a74feb26b9..a2c70ec5cd6e07ae46a91d59bdc1370dec905c37 100644 (file)
@@ -2893,6 +2893,8 @@ vect_bb_slp_scalar_cost (basic_block bb,
           else
            kind = scalar_store;
         }
+      else if (vect_nop_conversion_p (stmt_info))
+       continue;
       else
        kind = scalar_stmt;
       record_stmt_cost (cost_vec, 1, kind, stmt_info, 0, vect_body);
index 53f4189d939fa276e0cd3ec0f2d3ad012be051fe..c8a43ada16f774300e6488694cbd865719cf0ef0 100644 (file)
@@ -5281,6 +5281,29 @@ vectorizable_conversion (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
   return true;
 }
 
+/* Return true if we can assume from the scalar form of STMT_INFO that
+   neither the scalar nor the vector forms will generate code.  STMT_INFO
+   is known not to involve a data reference.  */
+
+bool
+vect_nop_conversion_p (stmt_vec_info stmt_info)
+{
+  gassign *stmt = dyn_cast <gassign *> (stmt_info->stmt);
+  if (!stmt)
+    return false;
+
+  tree lhs = gimple_assign_lhs (stmt);
+  tree_code code = gimple_assign_rhs_code (stmt);
+  tree rhs = gimple_assign_rhs1 (stmt);
+
+  if (code == SSA_NAME || code == VIEW_CONVERT_EXPR)
+    return true;
+
+  if (CONVERT_EXPR_CODE_P (code))
+    return tree_nop_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs));
+
+  return false;
+}
 
 /* Function vectorizable_assignment.
 
@@ -5396,7 +5419,9 @@ vectorizable_assignment (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi,
     {
       STMT_VINFO_TYPE (stmt_info) = assignment_vec_info_type;
       DUMP_VECT_SCOPE ("vectorizable_assignment");
-      vect_model_simple_cost (stmt_info, ncopies, dt, ndts, slp_node, cost_vec);
+      if (!vect_nop_conversion_p (stmt_info))
+       vect_model_simple_cost (stmt_info, ncopies, dt, ndts, slp_node,
+                               cost_vec);
       return true;
     }
 
index e556e0e98886de5de81eb44e013e31ff09136021..e93ccc74c66521467cbffb02f62327feb4cd7c96 100644 (file)
@@ -1650,6 +1650,7 @@ extern tree vect_get_vec_def_for_stmt_copy (vec_info *, tree);
 extern bool vect_transform_stmt (stmt_vec_info, gimple_stmt_iterator *,
                                 slp_tree, slp_instance);
 extern void vect_remove_stores (stmt_vec_info);
+extern bool vect_nop_conversion_p (stmt_vec_info);
 extern opt_result vect_analyze_stmt (stmt_vec_info, bool *, slp_tree,
                                     slp_instance, stmt_vector_for_cost *);
 extern void vect_get_load_cost (stmt_vec_info, int, bool,