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] tree-ssa-dom.c: Call update_stmt_if_modified beforeupdate_ssa.


Hi,

Attached is a patch to call update_stmt_if_modified before update_ssa.

While staring at tree_ssa_dominator_optimize, I noticed that we are
calling update_stmt_if_modified after calling update_ssa, which
doesn't make sense because update_ssa expects the operand cache to be
up-to-date.  (Note that update_ssa and its subroutines use things like
SET_USE, SET_DEF, and FOR_EACH_IMM_USE_FAST.)

The patch fixes this oddity by calling update_stmt_if_modified before
calling update_ssa.  For safety, I added to update_ssa assertion

  gcc_assert (!stmt_modified_p (stmt));

to prevent update_ssa from proceeding with out-of-date operand cache.

I tried to come up with a testcase such that without this patch, the
testcase results in wrong code, but I wasn't able to.  Without this
patch, only 0.3% of statements are marked as modified where we call
update_stmt_if_modified.

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2005-05-26  Kazu Hirata  <kazu@cs.umass.edu>

	* tree-into-ssa.c (update_ssa): Ensure that the operand cache
	is up-to-date.
	* tree-ssa-dom.c (tree_ssa_dominator_optimize): Call
	update_stmt_if_modified before calling update_ssa.

Index: tree-into-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-into-ssa.c,v
retrieving revision 2.56
diff -U6 -d -p -r2.56 tree-into-ssa.c
--- tree-into-ssa.c	25 May 2005 15:17:12 -0000	2.56
+++ tree-into-ssa.c	26 May 2005 09:24:53 -0000
@@ -2676,12 +2676,16 @@ update_ssa (unsigned update_flags)
 	  REGISTER_DEFS_IN_THIS_STMT (phi) = 0;
 	}
 
       for (si = bsi_start (bb); !bsi_end_p (si); bsi_next (&si))
 	{
 	  tree stmt = bsi_stmt (si);
+	  /* We are going to use the operand cache API, such as
+	     SET_USE, SET_DEF, and FOR_EACH_IMM_USE_FAST.  The operand
+	     cache for each statement should be up-to-date.  */
+	  gcc_assert (!stmt_modified_p (stmt));
 	  REWRITE_THIS_STMT (stmt) = 0;
 	  REGISTER_DEFS_IN_THIS_STMT (stmt) = 0;
 	}
     }
 
   /* Heuristic to avoid massive slow downs when the replacement
Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-dom.c,v
retrieving revision 2.113
diff -U6 -d -p -r2.113 tree-ssa-dom.c
--- tree-ssa-dom.c	24 May 2005 02:53:57 -0000	2.113
+++ tree-ssa-dom.c	26 May 2005 09:24:53 -0000
@@ -420,33 +420,33 @@ tree_ssa_dominator_optimize (void)
 	 for jump threading.  */
       mark_dfs_back_edges ();
 
       /* Recursively walk the dominator tree optimizing statements.  */
       walk_dominator_tree (&walk_data, ENTRY_BLOCK_PTR);
 
-      /* If we exposed any new variables, go ahead and put them into
-	 SSA form now, before we handle jump threading.  This simplifies
-	 interactions between rewriting of _DECL nodes into SSA form
-	 and rewriting SSA_NAME nodes into SSA form after block
-	 duplication and CFG manipulation.  */
-      update_ssa (TODO_update_ssa);
-
-      free_all_edge_infos ();
-
       {
 	block_stmt_iterator bsi;
 	basic_block bb;
 	FOR_EACH_BB (bb)
 	  {
 	    for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
 	      {
 		update_stmt_if_modified (bsi_stmt (bsi));
 	      }
 	  }
       }
 
+      /* If we exposed any new variables, go ahead and put them into
+	 SSA form now, before we handle jump threading.  This simplifies
+	 interactions between rewriting of _DECL nodes into SSA form
+	 and rewriting SSA_NAME nodes into SSA form after block
+	 duplication and CFG manipulation.  */
+      update_ssa (TODO_update_ssa);
+
+      free_all_edge_infos ();
+
       /* Thread jumps, creating duplicate blocks as needed.  */
       cfg_altered |= thread_through_all_blocks ();
 
       /* Removal of statements may make some EH edges dead.  Purge
 	 such edges from the CFG as needed.  */
       if (!bitmap_empty_p (need_eh_cleanup))


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