[PATCH,vect] Committed ppc cost model options

Jakub Jelinek jakub@redhat.com
Fri Dec 7 12:30:00 GMT 2007


On Thu, Dec 06, 2007 at 10:16:02AM -0600, Sebastian Pop wrote:
> I've committed the following patch after bootstrap and test on amd64-linux.

This breaks PR tree-optimization/34371, as LOOP_VINFO_NITERS is already
emitted elsewhere and thus needs unsharing.  This is an easy fix with
addition of two unshare_expr calls, but that led me to look at the
new
#define LOOP_VINFO_NITERS(L)          (L)->num_iters
/* Since LOOP_VINFO_NITERS can change after prologue peeling
   retain total unchanged scalar loop iterations for cost model.  */
#define LOOP_VINFO_NITERS_UNCHANGED(L)          (L)->num_iters
which all the new code sets as if it were two different fields, but it
is really an alias for the same thing.  That doesn't make any sense.

Either we keep it the same field, but then LOOP_VINFO_NITERS_UNCHANGED
macro should be just killed and LOOP_VINFO_NITERS used instead
to avoid confusion (this is what the first patch does).
Or, it makes sense and just tree-vectorizer.h mistakenly defines it to the
same field, then we need a new field (that's what the second patch does).

	Jakub
-------------- next part --------------
2007-12-07  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/34371
	* tree-vectorizer.h (LOOP_VINFO_NITERS_UNCHANGED): Removed.
	* tree-vectorizer.c (set_prologue_iterations,
	slpeel_tree_peel_loop_to_edge): Call unshare_expr on
	LOOP_VINFO_NITERS_UNCHANGED before using it.

	* gcc.c-torture/compile/20071207-1.c: New test.

--- gcc/tree-vect-analyze.c.jj	2007-12-07 12:21:06.000000000 +0100
+++ gcc/tree-vect-analyze.c	2007-12-07 12:53:09.000000000 +0100
@@ -4217,7 +4217,6 @@ vect_analyze_loop_form (struct loop *loo
 
   loop_vinfo = new_loop_vec_info (loop);
   LOOP_VINFO_NITERS (loop_vinfo) = number_of_iterations;
-  LOOP_VINFO_NITERS_UNCHANGED (loop_vinfo) = number_of_iterations;
 
   STMT_VINFO_TYPE (vinfo_for_stmt (loop_cond)) = loop_exit_ctrl_vec_info_type;
 
--- gcc/tree-vectorizer.h.jj	2007-12-07 12:21:06.000000000 +0100
+++ gcc/tree-vectorizer.h	2007-12-07 12:52:51.000000000 +0100
@@ -228,9 +228,6 @@ typedef struct _loop_vec_info {
 #define LOOP_VINFO_LOOP(L)            (L)->loop
 #define LOOP_VINFO_BBS(L)             (L)->bbs
 #define LOOP_VINFO_NITERS(L)          (L)->num_iters
-/* Since LOOP_VINFO_NITERS can change after prologue peeling
-   retain total unchanged scalar loop iterations for cost model.  */
-#define LOOP_VINFO_NITERS_UNCHANGED(L)          (L)->num_iters
 #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L)	(L)->min_profitable_iters
 #define LOOP_VINFO_VECTORIZABLE_P(L)  (L)->vectorizable
 #define LOOP_VINFO_VECT_FACTOR(L)     (L)->vectorization_factor
--- gcc/tree-vectorizer.c.jj	2007-12-07 12:21:06.000000000 +0100
+++ gcc/tree-vectorizer.c	2007-12-07 12:53:39.000000000 +0100
@@ -1037,7 +1037,7 @@ set_prologue_iterations (basic_block bb_
   tree gimplify_stmt_list;
   tree cost_pre_condition = NULL_TREE;
   tree scalar_loop_iters = 
-    LOOP_VINFO_NITERS_UNCHANGED (loop_vec_info_for_loop (loop));
+    unshare_expr (LOOP_VINFO_NITERS (loop_vec_info_for_loop (loop)));
 
   e = single_pred_edge (bb_before_first_loop);
   cond_bb = split_edge(e);
@@ -1154,8 +1154,6 @@ slpeel_tree_peel_loop_to_edge (struct lo
   edge exit_e = single_exit (loop);
   LOC loop_loc;
   tree cost_pre_condition = NULL_TREE;
-  tree scalar_loop_iters = 
-    LOOP_VINFO_NITERS_UNCHANGED (loop_vec_info_for_loop (loop));
   
   if (!slpeel_can_duplicate_loop_p (loop, e))
     return NULL;
@@ -1307,10 +1305,12 @@ slpeel_tree_peel_loop_to_edge (struct lo
 		     build_int_cst (TREE_TYPE (first_niters), 0));
       if (check_profitability)
 	{
-	    cost_pre_condition = 
+	  tree scalar_loop_iters
+	    = unshare_expr (LOOP_VINFO_NITERS (loop_vec_info_for_loop (loop)));
+	  cost_pre_condition = 
 	    build2 (LE_EXPR, boolean_type_node, scalar_loop_iters, 
 		    build_int_cst (TREE_TYPE (scalar_loop_iters), th));
-  
+
 	  pre_condition = fold_build2 (TRUTH_OR_EXPR, boolean_type_node,
 				       cost_pre_condition, pre_condition);
 	}
@@ -1653,7 +1653,6 @@ new_loop_vec_info (struct loop *loop)
 
   LOOP_VINFO_BBS (res) = bbs;
   LOOP_VINFO_NITERS (res) = NULL;
-  LOOP_VINFO_NITERS_UNCHANGED (res) = NULL;
   LOOP_VINFO_COST_MODEL_MIN_ITERS (res) = 0;
   LOOP_VINFO_VECTORIZABLE_P (res) = 0;
   LOOP_PEELING_FOR_ALIGNMENT (res) = 0;
--- gcc/testsuite/gcc.c-torture/compile/20071207-1.c.jj	2007-12-07 12:58:23.000000000 +0100
+++ gcc/testsuite/gcc.c-torture/compile/20071207-1.c	2007-12-07 12:57:37.000000000 +0100
@@ -0,0 +1,14 @@
+/* PR tree-optimization/34371 */
+/* Testcase by Martin Michlmayr <tbm@cyrius.com> */
+
+void centerln (int width, int ch, char *s)
+{
+  unsigned int sidebar;
+  int i;
+  char linet1[1000];
+  char linet2[100];
+  sidebar = (width - __builtin_strlen (s)) / 2;
+  for (i = 0; i < sidebar; i++)
+    linet2[i] = ch;
+  __builtin_strcpy (linet1, linet2);
+}
-------------- next part --------------
2007-12-07  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/34371
	* tree-vectorizer.h (struct _loop_vec_info): Add num_iters_unchanged
	field.
	(LOOP_VINFO_NITERS_UNCHANGED): Define to num_iters_unchanged field.
	* tree-vectorizer.c (set_prologue_iterations,
	slpeel_tree_peel_loop_to_edge): Call unshare_expr on
	LOOP_VINFO_NITERS_UNCHANGED before using it.

	* gcc.c-torture/compile/20071207-1.c: New test.

--- gcc/tree-vectorizer.h.jj	2007-12-07 12:21:06.000000000 +0100
+++ gcc/tree-vectorizer.h	2007-12-07 13:04:02.000000000 +0100
@@ -164,6 +164,7 @@ typedef struct _loop_vec_info {
 
   /* Number of iterations.  */
   tree num_iters;
+  tree num_iters_unchanged;
 
   /* Minimum number of iterations below which vectorization is expected to
      not be profitable (as estimated by the cost model). 
@@ -230,7 +231,7 @@ typedef struct _loop_vec_info {
 #define LOOP_VINFO_NITERS(L)          (L)->num_iters
 /* Since LOOP_VINFO_NITERS can change after prologue peeling
    retain total unchanged scalar loop iterations for cost model.  */
-#define LOOP_VINFO_NITERS_UNCHANGED(L)          (L)->num_iters
+#define LOOP_VINFO_NITERS_UNCHANGED(L)          (L)->num_iters_unchanged
 #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L)	(L)->min_profitable_iters
 #define LOOP_VINFO_VECTORIZABLE_P(L)  (L)->vectorizable
 #define LOOP_VINFO_VECT_FACTOR(L)     (L)->vectorization_factor
--- gcc/tree-vectorizer.c.jj	2007-12-07 12:21:06.000000000 +0100
+++ gcc/tree-vectorizer.c	2007-12-07 13:05:09.000000000 +0100
@@ -1037,7 +1037,7 @@ set_prologue_iterations (basic_block bb_
   tree gimplify_stmt_list;
   tree cost_pre_condition = NULL_TREE;
   tree scalar_loop_iters = 
-    LOOP_VINFO_NITERS_UNCHANGED (loop_vec_info_for_loop (loop));
+    unshare_expr (LOOP_VINFO_NITERS_UNCHANGED (loop_vec_info_for_loop (loop)));
 
   e = single_pred_edge (bb_before_first_loop);
   cond_bb = split_edge(e);
@@ -1154,8 +1154,6 @@ slpeel_tree_peel_loop_to_edge (struct lo
   edge exit_e = single_exit (loop);
   LOC loop_loc;
   tree cost_pre_condition = NULL_TREE;
-  tree scalar_loop_iters = 
-    LOOP_VINFO_NITERS_UNCHANGED (loop_vec_info_for_loop (loop));
   
   if (!slpeel_can_duplicate_loop_p (loop, e))
     return NULL;
@@ -1307,10 +1305,13 @@ slpeel_tree_peel_loop_to_edge (struct lo
 		     build_int_cst (TREE_TYPE (first_niters), 0));
       if (check_profitability)
 	{
-	    cost_pre_condition = 
+	  tree scalar_loop_iters
+	    = unshare_expr (LOOP_VINFO_NITERS_UNCHANGED
+					(loop_vec_info_for_loop (loop)));
+	  cost_pre_condition = 
 	    build2 (LE_EXPR, boolean_type_node, scalar_loop_iters, 
 		    build_int_cst (TREE_TYPE (scalar_loop_iters), th));
-  
+
 	  pre_condition = fold_build2 (TRUTH_OR_EXPR, boolean_type_node,
 				       cost_pre_condition, pre_condition);
 	}
--- gcc/testsuite/gcc.c-torture/compile/20071207-1.c.jj	2007-12-07 12:58:23.000000000 +0100
+++ gcc/testsuite/gcc.c-torture/compile/20071207-1.c	2007-12-07 12:57:37.000000000 +0100
@@ -0,0 +1,14 @@
+/* PR tree-optimization/34371 */
+/* Testcase by Martin Michlmayr <tbm@cyrius.com> */
+
+void centerln (int width, int ch, char *s)
+{
+  unsigned int sidebar;
+  int i;
+  char linet1[1000];
+  char linet2[100];
+  sidebar = (width - __builtin_strlen (s)) / 2;
+  for (i = 0; i < sidebar; i++)
+    linet2[i] = ch;
+  __builtin_strcpy (linet1, linet2);
+}


More information about the Gcc-patches mailing list