public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* update address taken: don't drop clobbers
@ 2014-06-28 22:33 Marc Glisse
  2014-06-29 23:38 ` SRA: " Marc Glisse
                   ` (2 more replies)
  0 siblings, 3 replies; 56+ messages in thread
From: Marc Glisse @ 2014-06-28 22:33 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1560 bytes --]

Hello,

we currently drop clobbers on variables whose address is not taken 
anymore. However, rewrite_stmt has code to replace them with an SSA_NAME 
with a default definition (an uninitialized variable), and I believe 
rewrite_update_stmt should do the same. This allows us to warn sometimes 
(see testcase), but during the debugging I also noticed several places 
where it allowed CCP to simplify further PHIs, so this is also an 
optimization.

In an earlier version of the patch, I was using
get_or_create_ssa_default_def (cfun, sym);
(I was reusing the same variable). This passed bootstrap+testsuite on all 
languages except for ada. Indeed, the compiler wanted to coalesce several 
SSA_NAMEs, including those new ones, in out-of-ssa, but couldn't. There 
are abnormal PHIs involved. Maybe it shouldn't have insisted on coalescing 
an undefined ssa_name, maybe something should have prevented us from 
reaching such a situation, but creating a new variable was the simplest 
workaround.

Some things could be done to improve the error message in uninit:
- getting the location of the variable,
- differenciating uninitialized from clobbered,
but that can come later.

Bootstrap+testsuite (all,obj-c++,ada,go) on x86_64-unknown-linux-gnu.

2014-06-30  Marc Glisse  <marc.glisse@inria.fr>

 	PR tree-optimization/60770
gcc/
 	* tree-ssa.c (execute_update_addresses_taken): Don't drop clobbers.
 	* tree-into-ssa.c (maybe_register_def): Replace clobbers with a
 	default definition.
gcc/testsuite/
 	* gcc.dg/tree-ssa/pr60770-1.c: New file.

-- 
Marc Glisse

[-- Attachment #2: Type: TEXT/PLAIN, Size: 3366 bytes --]

Index: gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c	(revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/pr60770-1.c	(working copy)
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O -Wall" } */
+
+int f(int n){
+  int*p;
+  {
+    int yyy=n;
+    p=&yyy;
+  }
+  return *p; /* { dg-warning "yyy" } */
+}
Index: gcc/tree-into-ssa.c
===================================================================
--- gcc/tree-into-ssa.c	(revision 212109)
+++ gcc/tree-into-ssa.c	(working copy)
@@ -1831,26 +1831,38 @@ maybe_register_def (def_operand_p def_p,
 {
   tree def = DEF_FROM_PTR (def_p);
   tree sym = DECL_P (def) ? def : SSA_NAME_VAR (def);
 
   /* If DEF is a naked symbol that needs renaming, create a new
      name for it.  */
   if (marked_for_renaming (sym))
     {
       if (DECL_P (def))
 	{
-	  tree tracked_var;
-
-	  def = make_ssa_name (def, stmt);
+	  if (gimple_clobber_p (stmt) && is_gimple_reg (sym))
+	    {
+	      /* Replace clobber stmts with a default def.  Create a new
+		 variable so we don't later think we must coalesce, which would
+		 fail with some ada abnormal PHIs.  Still, we try to keep a
+		 similar name so error messages make sense.  */
+	      unlink_stmt_vdef (stmt);
+	      gsi_replace (&gsi, gimple_build_nop (), true);
+	      tree id = DECL_NAME (sym);
+	      const char* name = id ? IDENTIFIER_POINTER (id) : 0;
+	      tree newvar = create_tmp_var (TREE_TYPE (sym), name);
+	      def = get_or_create_ssa_default_def (cfun, newvar);
+	    }
+	  else
+	    def = make_ssa_name (def, stmt);
 	  SET_DEF (def_p, def);
 
-	  tracked_var = target_for_debug_bind (sym);
+	  tree tracked_var = target_for_debug_bind (sym);
 	  if (tracked_var)
 	    {
 	      gimple note = gimple_build_debug_bind (tracked_var, def, stmt);
 	      /* If stmt ends the bb, insert the debug stmt on the single
 		 non-EH edge from the stmt.  */
 	      if (gsi_one_before_end_p (gsi) && stmt_ends_bb_p (stmt))
 		{
 		  basic_block bb = gsi_bb (gsi);
 		  edge_iterator ei;
 		  edge e, ef = NULL;
Index: gcc/tree-ssa.c
===================================================================
--- gcc/tree-ssa.c	(revision 212109)
+++ gcc/tree-ssa.c	(working copy)
@@ -1607,32 +1607,20 @@ execute_update_addresses_taken (void)
 		rhs = gimple_assign_rhs1 (stmt);
 		if (gimple_assign_lhs (stmt) != lhs
 		    && !useless_type_conversion_p (TREE_TYPE (lhs),
 						   TREE_TYPE (rhs)))
 		  rhs = fold_build1 (VIEW_CONVERT_EXPR,
 				     TREE_TYPE (lhs), rhs);
 
 		if (gimple_assign_lhs (stmt) != lhs)
 		  gimple_assign_set_lhs (stmt, lhs);
 
-		/* For var ={v} {CLOBBER}; where var lost
-		   TREE_ADDRESSABLE just remove the stmt.  */
-		if (DECL_P (lhs)
-		    && TREE_CLOBBER_P (rhs)
-		    && bitmap_bit_p (suitable_for_renaming, DECL_UID (lhs)))
-		  {
-		    unlink_stmt_vdef (stmt);
-      		    gsi_remove (&gsi, true);
-		    release_defs (stmt);
-		    continue;
-		  }
-
 		if (gimple_assign_rhs1 (stmt) != rhs)
 		  {
 		    gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
 		    gimple_assign_set_rhs_from_tree (&gsi, rhs);
 		  }
 	      }
 
 	    else if (gimple_code (stmt) == GIMPLE_CALL)
 	      {
 		unsigned i;

^ permalink raw reply	[flat|nested] 56+ messages in thread
* SRA: don't drop clobbers
@ 2014-11-03 12:59 Marc Glisse
  2014-11-03 15:44 ` Martin Jambor
  0 siblings, 1 reply; 56+ messages in thread
From: Marc Glisse @ 2014-11-03 12:59 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: TEXT/PLAIN, Size: 821 bytes --]

Hello,

now that the update_address_taken patch is in, let me re-post the SRA 
follow-up. With this patch, testcase pr60517.C (attached) has a use of an 
undefined variable at the time of the uninit pass. Sadly, while this 
warned with earlier versions of the other patch (when I was inserting 
default definitions of new variables), it does not anymore because we have 
TREE_NO_WARNING all over the place. Still, I believe this is a step in the 
right direction, and it passed bootstrap+testsuite (minus the new 
testcase). Would it be ok to commit the tree-sra.c change? Then I could 
close PR60770 (the warning itself is PR60517).

2014-11-03  Marc Glisse  <marc.glisse@inria.fr>

 	PR tree-optimization/60770
 	* tree-sra.c (clobber_subtree): New function.
 	(sra_modify_constructor_assign): Call it.

-- 
Marc Glisse

[-- Attachment #2: Type: TEXT/PLAIN, Size: 4108 bytes --]

Index: gcc/testsuite/g++.dg/tree-ssa/pr60517.C
===================================================================
--- gcc/testsuite/g++.dg/tree-ssa/pr60517.C	(revision 0)
+++ gcc/testsuite/g++.dg/tree-ssa/pr60517.C	(working copy)
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O -Wall" } */
+
+struct B {
+    double x[2];
+};
+struct A {
+    B b;
+    B getB() { return b; }
+};
+
+double foo(A a) {
+    double * x = &(a.getB().x[0]);
+    return x[0]; /* { dg-warning "" } */
+}
Index: gcc/tree-sra.c
===================================================================
--- gcc/tree-sra.c	(revision 217035)
+++ gcc/tree-sra.c	(working copy)
@@ -2716,20 +2716,51 @@ init_subtree_with_zero (struct access *a
       if (insert_after)
 	gsi_insert_after (gsi, ds, GSI_NEW_STMT);
       else
 	gsi_insert_before (gsi, ds, GSI_SAME_STMT);
     }
 
   for (child = access->first_child; child; child = child->next_sibling)
     init_subtree_with_zero (child, gsi, insert_after, loc);
 }
 
+/* Clobber all scalar replacements in an access subtree.  ACCESS is the the
+   root of the subtree to be processed.  GSI is the statement iterator used
+   for inserting statements which are added after the current statement if
+   INSERT_AFTER is true or before it otherwise.  */
+
+static void
+clobber_subtree (struct access *access, gimple_stmt_iterator *gsi,
+		bool insert_after, location_t loc)
+
+{
+  struct access *child;
+
+  if (access->grp_to_be_replaced)
+    {
+      tree rep = get_access_replacement (access);
+      tree clobber = build_constructor (access->type, NULL);
+      TREE_THIS_VOLATILE (clobber) = 1;
+      gimple stmt = gimple_build_assign (rep, clobber);
+
+      if (insert_after)
+	gsi_insert_after (gsi, stmt, GSI_NEW_STMT);
+      else
+	gsi_insert_before (gsi, stmt, GSI_SAME_STMT);
+      update_stmt (stmt);
+      gimple_set_location (stmt, loc);
+    }
+
+  for (child = access->first_child; child; child = child->next_sibling)
+    clobber_subtree (child, gsi, insert_after, loc);
+}
+
 /* Search for an access representative for the given expression EXPR and
    return it or NULL if it cannot be found.  */
 
 static struct access *
 get_access_for_expr (tree expr)
 {
   HOST_WIDE_INT offset, size, max_size;
   tree base;
 
   /* FIXME: This should not be necessary but Ada produces V_C_Es with a type of
@@ -3028,43 +3059,41 @@ enum assignment_mod_result { SRA_AM_NONE
 			     SRA_AM_REMOVED };  /* stmt eliminated */
 
 /* Modify assignments with a CONSTRUCTOR on their RHS.  STMT contains a pointer
    to the assignment and GSI is the statement iterator pointing at it.  Returns
    the same values as sra_modify_assign.  */
 
 static enum assignment_mod_result
 sra_modify_constructor_assign (gimple stmt, gimple_stmt_iterator *gsi)
 {
   tree lhs = gimple_assign_lhs (stmt);
-  struct access *acc;
-  location_t loc;
-
-  acc = get_access_for_expr (lhs);
+  struct access *acc = get_access_for_expr (lhs);
   if (!acc)
     return SRA_AM_NONE;
+  location_t loc = gimple_location (stmt);
 
   if (gimple_clobber_p (stmt))
     {
-      /* Remove clobbers of fully scalarized variables, otherwise
-	 do nothing.  */
+      /* Clobber the replacement variable.  */
+      clobber_subtree (acc, gsi, !acc->grp_covered, loc);
+      /* Remove clobbers of fully scalarized variables, they are dead.  */
       if (acc->grp_covered)
 	{
 	  unlink_stmt_vdef (stmt);
 	  gsi_remove (gsi, true);
 	  release_defs (stmt);
 	  return SRA_AM_REMOVED;
 	}
       else
-	return SRA_AM_NONE;
+	return SRA_AM_MODIFIED;
     }
 
-  loc = gimple_location (stmt);
   if (vec_safe_length (CONSTRUCTOR_ELTS (gimple_assign_rhs1 (stmt))) > 0)
     {
       /* I have never seen this code path trigger but if it can happen the
 	 following should handle it gracefully.  */
       if (access_has_children_p (acc))
 	generate_subtree_copies (acc->first_child, lhs, acc->offset, 0, 0, gsi,
 				 true, true, loc);
       return SRA_AM_MODIFIED;
     }
 

^ permalink raw reply	[flat|nested] 56+ messages in thread

end of thread, other threads:[~2014-11-21 14:34 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-28 22:33 update address taken: don't drop clobbers Marc Glisse
2014-06-29 23:38 ` SRA: " Marc Glisse
2014-07-07  8:56   ` Richard Biener
2014-07-07  9:32     ` Marc Glisse
2014-07-07 18:32       ` Richard Biener
2014-07-07 20:15         ` Marc Glisse
2014-07-07 16:59     ` Jeff Law
2014-07-10 14:55   ` Richard Biener
2014-07-10 15:01     ` Jakub Jelinek
2014-06-30 19:31 ` update address taken: " Jeff Law
2014-07-06 14:24   ` Marc Glisse
2014-07-06 14:54     ` pinskia
2014-07-06 15:01       ` Marc Glisse
2014-07-07 10:21     ` Richard Biener
2014-07-07 17:20     ` Jeff Law
2014-07-08 13:31       ` Marc Glisse
2014-07-10 15:10 ` Richard Biener
2014-07-10 15:49   ` Michael Matz
2014-07-10 18:23     ` Jeff Law
2014-07-11  8:10       ` Richard Biener
2014-07-11  8:14         ` Richard Biener
2014-07-11 12:06       ` Michael Matz
2014-07-11 17:16         ` Jeff Law
2014-07-12  6:15   ` Marc Glisse
2014-07-24 13:06     ` Richard Biener
2014-07-27 11:53   ` Marc Glisse
2014-07-27 18:01   ` Marc Glisse
2014-09-07 15:28     ` Marc Glisse
2014-10-15 14:36       ` Marc Glisse
2014-10-15 16:12         ` Jeff Law
2014-10-16 11:20           ` Richard Biener
2014-10-16 14:11             ` Marc Glisse
2014-10-16 14:34               ` Richard Biener
2014-10-16 17:29               ` Jeff Law
2014-10-16 17:58                 ` Richard Biener
2014-10-16 18:37                   ` Jeff Law
2014-10-17 20:46                     ` Marc Glisse
2014-10-24 20:22                       ` Jeff Law
2014-10-25  8:06                         ` Marc Glisse
2014-10-31 21:06                           ` Jeff Law
2014-10-25 17:14                         ` Marc Glisse
2014-10-31 11:12                           ` Richard Biener
2014-11-02 10:34                             ` Marc Glisse
2014-11-03  9:06                               ` Richard Biener
2014-10-31 21:16                           ` Jeff Law
2014-10-16 17:23             ` Jeff Law
2014-10-18 22:23   ` Marc Glisse
2014-10-24 20:19     ` Jeff Law
2014-11-03 12:59 SRA: " Marc Glisse
2014-11-03 15:44 ` Martin Jambor
2014-11-03 16:17   ` Marc Glisse
2014-11-03 17:01     ` Martin Jambor
2014-11-03 18:58       ` Marc Glisse
2014-11-03 21:46         ` Marc Glisse
2014-11-20 18:19           ` Martin Jambor
2014-11-21 15:21             ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).