[PATCH v2 5/5] vect: Cost niter conditions.

Robin Dapp <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <[email protected]>
From: Robin Dapp <[email protected]>

This patch adjusts niter-condition costing.  Instead of just one
vector statements, it counts the number of ANDed terms and costs
that many scalar statements.

gcc/ChangeLog:

	* tree-vect-loop.cc (vect_estimate_min_profitable_iters): Adjust
	niter condition costing.
---
 gcc/tree-vect-loop.cc | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 54f8912b894..410bf7aca4b 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -4128,8 +4128,23 @@ vect_estimate_min_profitable_iters (loop_vec_info loop_vinfo,
   /* Requires loop versioning with niter checks.  */
   if (LOOP_REQUIRES_VERSIONING_FOR_NITERS (loop_vinfo))
     {
+      tree assum = LOOP_VINFO_NITERS_ASSUMPTIONS (loop_vinfo);
+
+      /* Count the ANDs and comparisons in the assumption tree.  */
+      auto count_conditions = [] (tree *t, int *, void *nconditions) -> tree
+	{
+	  if (EXPR_P (*t)
+	      && (TREE_CODE (*t) == BIT_AND_EXPR
+		  || TREE_CODE_CLASS (TREE_CODE (*t)) == tcc_comparison))
+	    (*(int *) nconditions)++;
+	  return NULL_TREE;
+	};
+
+      int nconditions = 0;
+      walk_tree_without_duplicates (&assum, count_conditions, &nconditions);
+
       /*  FIXME: Make cost depend on complexity of individual check.  */
-      (void) add_stmt_cost (target_cost_data, 1, vector_stmt,
+      (void) add_stmt_cost (target_cost_data, nconditions, scalar_stmt,
 			    NULL, NULL, NULL_TREE, 0, vect_prologue);
       if (dump_enabled_p ())
 	dump_printf (MSG_NOTE,
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.