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 2 p+ issues and another parloop bug (PR tree-optimization/33453)


Hi!

In PR33453 there is a whole bunch of unrelated issues.

The tree-data-ref.c hunk together with 20071203-1.c fixes the #c3 testcase.

The canonicalize_loop_ivs fixes the p+ bug on
/* { dg-do compile } */
/* { dg-options "-O3 -ftree-parallelize-loops=4" } */
struct T
{
  int t;
  struct { short s1, s2, s3, s4 } *s;
};

void
foo (int *a, int *b, int *c, int *d, struct T *e)
{
  int i;
  for (i = 0; i < e->t; i++)
    {
      e->s[i].s1 = a[i];
      e->s[i].s2 = b[i];
      e->s[i].s3 = c[i];
      e->s[i].s4 = d[i];
    }
}

In both cases gcc was trying to build PLUS_EXPR with POINTER_TYPE_P
vars.

The third problem is another ICE on the above testcase when
canonicalize_loop_ivs is fixed.  It creates a new VAR_DECL for copy of var,
but doesn't copy over various flags.  The separate_decls_in_loop_name
copies DECL_GIMPLE_REG_P which is enough to fix this ICE, but it would be
good if the tree-parloops.c authors could spend some time thinking about
other flags.  E.g. omp-low.c's copy_var_decl copies:
  TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (var);
  TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (var);
  DECL_GIMPLE_REG_P (copy) = DECL_GIMPLE_REG_P (var);
  DECL_NO_TBAA_P (copy) = DECL_NO_TBAA_P (var);
  DECL_ARTIFICIAL (copy) = DECL_ARTIFICIAL (var);
  DECL_IGNORED_P (copy) = DECL_IGNORED_P (var);
  DECL_CONTEXT (copy) = DECL_CONTEXT (var); 
and sets TREE_USED.  When I fix that there is another ICE in
get_smt_for, which would be better addressed by parloop authors
(as I'm afraid that is not the last one, and 3 unrelated ICEs on very
trivial testcase already is a lot).

Regtested on x86_64-linux, full bootstrap will start soon.
Ok for trunk?

2007-12-03  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/33453
	* tree-data-ref.c (split_constant_offset): Use POINTER_PLUS_EXPR
	for pointer addition.
	* tree-parloops.c (canonicalize_loop_ivs): Likewise.
	(separate_decls_in_loop_name): Copy DECL_GIMPLE_REG_P from var to
	var_copy.

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

--- gcc/tree-data-ref.c.jj	2007-11-10 01:18:06.000000000 +0100
+++ gcc/tree-data-ref.c	2007-12-03 15:46:46.000000000 +0100
@@ -555,9 +555,12 @@ split_constant_offset (tree exp, tree *v
 	  {
 	    split_constant_offset (poffset, &poffset, &off1);
 	    off0 = size_binop (PLUS_EXPR, off0, off1);
-	    base = fold_build2 (PLUS_EXPR, TREE_TYPE (base),
-				base,
-				fold_convert (TREE_TYPE (base), poffset));
+	    if (POINTER_TYPE_P (TREE_TYPE (base)))
+	      base = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (base),
+				  base, fold_convert (sizetype, poffset));
+	    else
+	      base = fold_build2 (PLUS_EXPR, TREE_TYPE (base), base,
+				  fold_convert (TREE_TYPE (base), poffset));
 	  }
 
 	var0 = fold_convert (type, base);
--- gcc/tree-parloops.c.jj	2007-11-26 22:14:08.000000000 +0100
+++ gcc/tree-parloops.c	2007-12-03 15:37:58.000000000 +0100
@@ -687,6 +687,7 @@ separate_decls_in_loop_name (tree name,
   if (!*dslot)
     {
       var_copy = create_tmp_var (TREE_TYPE (var), get_name (var));
+      DECL_GIMPLE_REG_P (var_copy) = DECL_GIMPLE_REG_P (var);
       add_referenced_var (var_copy);
       nielt = XNEW (struct int_tree_map);
       nielt->uid = uid;
@@ -1266,7 +1267,7 @@ static void
 canonicalize_loop_ivs (struct loop *loop, htab_t reduction_list, tree nit)
 {
   unsigned precision = TYPE_PRECISION (TREE_TYPE (nit));
-  tree phi, prev, res, type, var_before, val, atype, t, next;
+  tree phi, prev, res, type, var_before, val, atype, mtype, t, next;
   block_stmt_iterator bsi;
   bool ok;
   affine_iv iv;
@@ -1313,11 +1314,12 @@ canonicalize_loop_ivs (struct loop *loop
       remove_phi_node (phi, prev, false);
 
       atype = TREE_TYPE (res);
-      val = fold_build2 (PLUS_EXPR, atype,
-			 unshare_expr (iv.base),
-			 fold_build2 (MULT_EXPR, atype,
-				      unshare_expr (iv.step),
-				      fold_convert (atype, var_before)));
+      mtype = POINTER_TYPE_P (atype) ? sizetype : atype;
+      val = fold_build2 (MULT_EXPR, mtype, unshare_expr (iv.step),
+			 fold_convert (mtype, var_before));
+      val = fold_build2 (POINTER_TYPE_P (atype)
+			 ? POINTER_PLUS_EXPR : PLUS_EXPR,
+			 atype, unshare_expr (iv.base), val);
       val = force_gimple_operand_bsi (&bsi, val, false, NULL_TREE, true,
 				      BSI_SAME_STMT);
       t = build_gimple_modify_stmt (res, val);
--- gcc/testsuite/gcc.c-torture/compile/20071203-1.c.jj	2007-12-03 16:01:38.000000000 +0100
+++ gcc/testsuite/gcc.c-torture/compile/20071203-1.c	2007-12-03 14:28:50.000000000 +0100
@@ -0,0 +1,12 @@
+/* Testcase by Martin Michlmayr <tbm@cyrius.com> */
+
+struct User { char username[10]; };
+
+void
+auth_set_username (struct User *user)
+{
+  char *d;
+  char ch;
+  d = user->username + (user->username[0] == '~');
+  while ((ch = *d++) != '\0') /* do nothing */ ;
+}

	Jakub


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