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]

[graphite] fix pr38786


Hi,

The attached patch fixes PR38786: in the expansion of scalar variables
we used to stop at the first memory load, and this without collecting
the memory indexing computation.  With this patch we also collect the
indexing computation.  Regstrapped on trunk on amd64-linux with
BOOT_CFLAGS="-g -O2 -fgraphite-identity -floop-block".
Ok for trunk?

Thanks,
Sebastian Pop
--
AMD - GNU Tools
2009-01-11  Sebastian Pop  <sebastian.pop@amd.com>

	PR tree-optimization/38786
	* testsuite/gcc.dg/graphite/pr38786.c: New.
	* graphite.c (expand_scalar_variables_ssa_name): New, outlined from
	the SSA_NAME case of expand_scalar_variables_expr.
	(expand_scalar_variables_expr): Also gather the scalar computation
	used to index the memory access.
	(expand_scalar_variables_stmt): Pass to expand_scalar_variables_expr
	the gimple_stmt_iterator where it inserts new code.

Index: testsuite/gcc.dg/graphite/pr38786.c
===================================================================
--- testsuite/gcc.dg/graphite/pr38786.c	(revision 0)
+++ testsuite/gcc.dg/graphite/pr38786.c	(revision 0)
@@ -0,0 +1,20 @@
+/* { dg-options "-O2 -fgraphite-identity" } */
+
+typedef struct
+{
+  int ****cofAC;
+} ImageParameters;
+typedef struct
+{
+  int ****cofAC;
+} RD_DATA;
+extern RD_DATA *rdopt;
+extern ImageParameters *img;
+dummy_slice_too_big (int bits_slice)
+{
+  int i, j, k, l;
+  for (j = 0; j < 4; j++)
+    for (k = 0; k < 2; k++)
+      for (l = 0; l < 65; l++)
+	img->cofAC[i][j][k][l] = rdopt->cofAC[i][j][k][l];
+}
Index: graphite.c
===================================================================
--- graphite.c	(revision 143257)
+++ graphite.c	(working copy)
@@ -4091,6 +4091,50 @@ is_iv (tree name)
 
 static void expand_scalar_variables_stmt (gimple, basic_block, scop_p,
 					  loop_p, htab_t);
+static tree
+expand_scalar_variables_expr (tree, tree, enum tree_code, tree, basic_block,
+			      scop_p, loop_p, htab_t, gimple_stmt_iterator *);
+
+/* Helper function for expand_scalar_variables_expr.  */
+
+static tree
+expand_scalar_variables_ssa_name (tree type, tree op0, basic_block bb,
+				  scop_p scop, loop_p old_loop_father,
+				  htab_t map, gimple_stmt_iterator *gsi)
+{
+  tree var0, var1;
+  gimple def_stmt;
+  enum tree_code subcode;
+      
+  if (is_parameter (scop, op0)
+      || is_iv (op0))
+    return get_new_name_from_old_name (map, op0);
+      
+  def_stmt = SSA_NAME_DEF_STMT (op0);
+      
+  if (gimple_bb (def_stmt) == bb)
+    {
+      /* If the defining statement is in the basic block already
+	 we do not need to create a new expression for it, we
+	 only need to ensure its operands are expanded.  */
+      expand_scalar_variables_stmt (def_stmt, bb, scop,
+				    old_loop_father, map);
+      return get_new_name_from_old_name (map, op0);
+    }
+  else
+    {
+      if (gimple_code (def_stmt) != GIMPLE_ASSIGN
+	  || !bb_in_scop_p (gimple_bb (def_stmt), scop))
+	return get_new_name_from_old_name (map, op0);
+
+      var0 = gimple_assign_rhs1 (def_stmt);
+      subcode = gimple_assign_rhs_code (def_stmt);
+      var1 = gimple_assign_rhs2 (def_stmt);
+
+      return expand_scalar_variables_expr (type, var0, subcode, var1, bb, scop,
+					   old_loop_father, map, gsi);
+    }
+}
 
 /* Constructs a tree which only contains old_ivs and parameters.  Any
    other variables that are defined outside BB will be eliminated by
@@ -4100,21 +4144,62 @@ static void expand_scalar_variables_stmt
 static tree
 expand_scalar_variables_expr (tree type, tree op0, enum tree_code code, 
 			      tree op1, basic_block bb, scop_p scop, 
-			      loop_p old_loop_father, htab_t map)
+			      loop_p old_loop_father, htab_t map,
+			      gimple_stmt_iterator *gsi)
 {
-  if ((TREE_CODE_CLASS (code) == tcc_constant
-       && code == INTEGER_CST)
-      || TREE_CODE_CLASS (code) == tcc_reference)
+  if (TREE_CODE_CLASS (code) == tcc_constant
+      && code == INTEGER_CST)
     return op0;
 
+  /* For data references we have to duplicate also its memory
+     indexing.  */
+  if (TREE_CODE_CLASS (code) == tcc_reference)
+    {
+      switch (code)
+	{
+	case INDIRECT_REF:
+	  {
+	    tree old_name = TREE_OPERAND (op0, 0);
+	    tree expr = expand_scalar_variables_ssa_name
+	      (type, old_name, bb, scop, old_loop_father, map, gsi);
+	    tree new_name = force_gimple_operand_gsi (gsi, expr, true, NULL,
+						      true, GSI_SAME_STMT);
+
+	    set_symbol_mem_tag (SSA_NAME_VAR (new_name),
+				symbol_mem_tag (SSA_NAME_VAR (old_name)));
+	    return fold_build1 (code, type, new_name);
+	  }
+
+	case ARRAY_REF:
+	  {
+	    tree op00 = TREE_OPERAND (op0, 0);
+	    tree op01 = TREE_OPERAND (op0, 1);
+	    tree op02 = TREE_OPERAND (op0, 2);
+	    tree op03 = TREE_OPERAND (op0, 3);
+	    tree base = expand_scalar_variables_expr
+	      (TREE_TYPE (op00), op00, TREE_CODE (op00), NULL, bb, scop,
+	       old_loop_father, map, gsi);
+	    tree subscript = expand_scalar_variables_expr
+	      (TREE_TYPE (op01), op01, TREE_CODE (op01), NULL, bb, scop,
+	       old_loop_father, map, gsi);
+
+	    return build4 (ARRAY_REF, type, base, subscript, op02, op03);
+	  }
+
+	default:
+	  /* The above cases should catch everything.  */
+	  gcc_unreachable ();
+	}
+    }
+
   if (TREE_CODE_CLASS (code) == tcc_unary)
     {
       tree op0_type = TREE_TYPE (op0);
       enum tree_code op0_code = TREE_CODE (op0);
       tree op0_expr = 
-	expand_scalar_variables_expr (op0_type, op0, op0_code,
-				      NULL, bb, scop, old_loop_father, map);
-
+	expand_scalar_variables_expr (op0_type, op0, op0_code, NULL, bb, scop,
+				      old_loop_father, map, gsi);
+  
       return fold_build1 (code, type, op0_expr);
     }
 
@@ -4123,52 +4208,20 @@ expand_scalar_variables_expr (tree type,
       tree op0_type = TREE_TYPE (op0);
       enum tree_code op0_code = TREE_CODE (op0);
       tree op0_expr = 
-	expand_scalar_variables_expr (op0_type, op0, op0_code,
-				      NULL, bb, scop, old_loop_father, map);
+	expand_scalar_variables_expr (op0_type, op0, op0_code, NULL, bb, scop,
+				      old_loop_father, map, gsi);
       tree op1_type = TREE_TYPE (op1);
       enum tree_code op1_code = TREE_CODE (op1);
       tree op1_expr = 
-	expand_scalar_variables_expr (op1_type, op1, op1_code,
-				      NULL, bb, scop, old_loop_father, map);
+	expand_scalar_variables_expr (op1_type, op1, op1_code, NULL, bb, scop,
+				      old_loop_father, map, gsi);
 
       return fold_build2 (code, type, op0_expr, op1_expr);
     }
 
   if (code == SSA_NAME)
-    {
-      tree var0, var1;
-      gimple def_stmt;
-      enum tree_code subcode;
-      
-      if (is_parameter (scop, op0)
-	  || is_iv (op0))
-	return get_new_name_from_old_name (map, op0);
-      
-      def_stmt = SSA_NAME_DEF_STMT (op0);
-      
-      if (gimple_bb (def_stmt) == bb)
-	{
-	  /* If the defining statement is in the basic block already
-	     we do not need to create a new expression for it, we
-	     only need to ensure its operands are expanded.  */
-	  expand_scalar_variables_stmt (def_stmt, bb, scop,
-					old_loop_father, map);
-	  return get_new_name_from_old_name (map, op0);
-	}
-      else
-	{
-	  if (gimple_code (def_stmt) != GIMPLE_ASSIGN
-	      || !bb_in_scop_p (gimple_bb (def_stmt), scop))
-	    return get_new_name_from_old_name (map, op0);
-
-	  var0 = gimple_assign_rhs1 (def_stmt);
-	  subcode = gimple_assign_rhs_code (def_stmt);
-	  var1 = gimple_assign_rhs2 (def_stmt);
-
-	  return expand_scalar_variables_expr (type, var0, subcode, var1,
-					       bb, scop, old_loop_father, map);
-	}
-    }
+    return expand_scalar_variables_ssa_name (type, op0, bb, scop,
+					     old_loop_father, map, gsi);
 
   gcc_unreachable ();
   return NULL;
@@ -4184,6 +4237,7 @@ expand_scalar_variables_stmt (gimple stm
 {
   ssa_op_iter iter;
   use_operand_p use_p;
+  gimple_stmt_iterator gsi = gsi_after_labels (bb);
 
   FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE)
     {
@@ -4191,10 +4245,10 @@ expand_scalar_variables_stmt (gimple stm
       tree type = TREE_TYPE (use);
       enum tree_code code = TREE_CODE (use);
       tree use_expr = expand_scalar_variables_expr (type, use, code, NULL, bb,
-						    scop, old_loop_father, map);
+						    scop, old_loop_father, map,
+						    &gsi);
       if (use_expr != use)
 	{
-	  gimple_stmt_iterator gsi = gsi_after_labels (bb);
 	  tree new_use =
 	    force_gimple_operand_gsi (&gsi, use_expr, true, NULL,
 				      true, GSI_NEW_STMT);

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