This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix PR37686: Correct how lambda gets the loop index for the matrix representation of array accesses


Hi,

Instead of looking at the difference between loop->num
we should do exactly what graphite is doing: register loops belonging
to the loop nest in a VEC, then iterate over the loop nest to find the
index in the Access Matrix.  Okay for trunk after bootstrap and test?

Thanks,
Sebastian Pop
--
AMD - GNU Tools
	PR tree-optimization/37686
	* testsuite/gcc.dg/tree-ssa/pr37686.c: New.
	* tree-loop-linear.c (linear_transform_loops): Build a
	loop nest vector.  Pass it to lambda_compute_access_matrices.
	* tree-data-ref.h (struct access_matrix): Store the loop nest
	relative to which it encodes the information.
	(AM_LOOP_NEST_NUM): Renamed AM_LOOP_NEST.
	(am_vector_index_for_loop): Reimplemented: iterate over the
	loop nest for finding the loop index in the access matrix.
	(lambda_compute_access_matrices): Update declaration.
	* lambda-code.c (build_access_matrix): Pass the loop nest and
	record it.
	(lambda_compute_access_matrices): Same.

Index: tree-loop-linear.c
===================================================================
--- tree-loop-linear.c	(revision 140668)
+++ tree-loop-linear.c	(working copy)
@@ -333,11 +333,16 @@ linear_transform_loops (void)
       lambda_loopnest before, after;
       lambda_trans_matrix trans;
       struct obstack lambda_obstack;
+      struct loop *loop;
+      VEC(loop_p,heap) *nest = VEC_alloc (loop_p, heap, 3);
 
       depth = perfect_loop_nest_depth (loop_nest);
       if (depth == 0)
 	continue;
 
+      for (loop = loop_nest; loop; loop = loop->inner)
+	VEC_safe_push (loop_p, heap, nest, loop);
+
       gcc_obstack_init (&lambda_obstack);
       VEC_truncate (tree, oldivs, 0);
       VEC_truncate (tree, invariants, 0);
@@ -350,8 +355,7 @@ linear_transform_loops (void)
 	goto free_and_continue;
       
       lambda_collect_parameters (datarefs, &lambda_parameters);
-      if (!lambda_compute_access_matrices (datarefs, lambda_parameters,
-					   loop_nest->num))
+      if (!lambda_compute_access_matrices (datarefs, lambda_parameters, nest))
 	goto free_and_continue;
 
       if (dump_file && (dump_flags & TDF_DETAILS))
@@ -410,6 +414,7 @@ linear_transform_loops (void)
       obstack_free (&lambda_obstack, NULL);
       free_dependence_relations (dependence_relations);
       free_data_refs (datarefs);
+      VEC_free (loop_p, heap, nest);
     }
 
   for (i = 0; VEC_iterate (gimple, remove_ivs, i, oldiv_stmt); i++)
Index: testsuite/gcc.dg/tree-ssa/pr37686.c
===================================================================
--- testsuite/gcc.dg/tree-ssa/pr37686.c	(revision 0)
+++ testsuite/gcc.dg/tree-ssa/pr37686.c	(revision 0)
@@ -0,0 +1,48 @@
+/* { dg-do compile { target powerpc*-*-* } } */
+/* { dg-options "-mcpu=power4 -m64 -mtune=cell -O3 -ftree-loop-linear --param ggc-min-expand=0 --param ggc-min-heapsize=0 -funroll-loops -fpreprocessed" } */
+
+unsigned char inUse[256];
+unsigned char len[6][258];
+int code[6][258];
+unsigned int crc32Table[256] = { };
+  unsigned int getGlobalCRC (void) { }
+  int bsLive;
+void bsW (int n, unsigned int v) {
+ while (bsLive >= 8) {}
+ }
+ void hbAssignCodes (int * code,         unsigned char * length, int minLen,
+int maxLen, int alphaSize) {
+   int n, vec, i;
+   for (n = minLen;n <= maxLen;n++)
+       for (i = 0; i < alphaSize;i++)
+      code[i] = vec;
+   }
+  void sendMTFValues (void) {
+   int v, t, i, j, gs, ge, totc, bt, bc, iter;
+   int nSelectors, alphaSize, minLen, maxLen, selCtr;
+   int nGroups, nBytes;
+ {
+    while (1)
+  {
+  break;
+  }
+       hbAssignCodes (&code[t][0], &len[t][0], minLen, maxLen, alphaSize);
+     unsigned char inUse16[16];
+     for (i = 0;i < 16;i++)
+ if (inUse16[i])
+  {
+      for (j = 0;j < 16;j++)
+   if (inUse[i * 16 + j])    { }
+    }
+   }
+   for (i = 0; i < nSelectors;i++)     { }
+   for (t = 0; t < nGroups;t++)
+ {
+       int curr = len[t][0];
+       for (i = 0; i < alphaSize;i++)
+          while (curr < len[t][i])     { }
+     }
+   while (1)
+       for (i = gs; i <= ge;i++)  { }
+ }
+
Index: tree-data-ref.h
===================================================================
--- tree-data-ref.h	(revision 140668)
+++ tree-data-ref.h	(working copy)
@@ -128,13 +128,13 @@ typedef struct scop *scop_p;
 */
 struct access_matrix
 {
-  int loop_nest_num;
+  VEC (loop_p, heap) *loop_nest;
   int nb_induction_vars;
   VEC (tree, heap) *parameters;
   VEC (lambda_vector, heap) *matrix;
 };
 
-#define AM_LOOP_NEST_NUM(M) (M)->loop_nest_num
+#define AM_LOOP_NEST(M) (M)->loop_nest
 #define AM_NB_INDUCTION_VARS(M) (M)->nb_induction_vars
 #define AM_PARAMETERS(M) (M)->parameters
 #define AM_MATRIX(M) (M)->matrix
@@ -149,8 +149,14 @@ struct access_matrix
 static inline int
 am_vector_index_for_loop (struct access_matrix *access_matrix, int loop_num)
 {
-  gcc_assert (loop_num >= AM_LOOP_NEST_NUM (access_matrix));
-  return loop_num - AM_LOOP_NEST_NUM (access_matrix);
+  int i;
+  loop_p l;
+
+  for (i = 0; VEC_iterate (loop_p, AM_LOOP_NEST (access_matrix), i, l); i++)
+    if (l->num == loop_num)
+      return i;
+
+  gcc_unreachable();
 }
 
 int access_matrix_get_index_for_parameter (tree, struct access_matrix *);
@@ -581,7 +587,7 @@ bool lambda_transform_legal_p (lambda_tr
 void lambda_collect_parameters (VEC (data_reference_p, heap) *,
 				VEC (tree, heap) **);
 bool lambda_compute_access_matrices (VEC (data_reference_p, heap) *,
-				     VEC (tree, heap) *, int);
+				     VEC (tree, heap) *, VEC (loop_p, heap) *);
 
 /* In tree-data-ref.c  */
 void split_constant_offset (tree , tree *, tree *);
Index: lambda-code.c
===================================================================
--- lambda-code.c	(revision 140668)
+++ lambda-code.c	(working copy)
@@ -2786,17 +2786,15 @@ av_for_af (tree access_fun, lambda_vecto
 
 static bool
 build_access_matrix (data_reference_p data_reference,
-		     VEC (tree, heap) *parameters, int loop_nest_num)
+		     VEC (tree, heap) *parameters, VEC (loop_p, heap) *nest)
 {
   struct access_matrix *am = GGC_NEW (struct access_matrix);
   unsigned i, ndim = DR_NUM_DIMENSIONS (data_reference);
-  struct loop *loop = gimple_bb (DR_STMT (data_reference))->loop_father;
-  struct loop *loop_nest = get_loop (loop_nest_num);
-  unsigned nivs = loop_depth (loop) - loop_depth (loop_nest) + 1;
+  unsigned nivs = VEC_length (loop_p, nest);
   unsigned lambda_nb_columns;
   lambda_vector_vec_p matrix;
 
-  AM_LOOP_NEST_NUM (am) = loop_nest_num;
+  AM_LOOP_NEST (am) = nest;
   AM_NB_INDUCTION_VARS (am) = nivs;
   AM_PARAMETERS (am) = parameters;
 
@@ -2824,13 +2822,13 @@ build_access_matrix (data_reference_p da
 bool
 lambda_compute_access_matrices (VEC (data_reference_p, heap) *datarefs,
 				VEC (tree, heap) *parameters,
-				int loop_nest_num)
+				VEC (loop_p, heap) *nest)
 {
   data_reference_p dataref;
   unsigned ix;
 
   for (ix = 0; VEC_iterate (data_reference_p, datarefs, ix, dataref); ix++)
-    if (!build_access_matrix (dataref, parameters, loop_nest_num))
+    if (!build_access_matrix (dataref, parameters, nest))
       return false;
 
   return true;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]