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; 48+ 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] 48+ messages in thread

end of thread, other threads:[~2014-11-03  9:06 UTC | newest]

Thread overview: 48+ 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

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).