[tree-ssa] More jump threading improvements

Pop Sebastian pop@gauvain.u-strasbg.fr
Thu Jan 29 16:00:00 GMT 2004


On Tue, Jan 27, 2004 at 11:44:38AM -0700, law@redhat.com wrote:
> Checking loop_of_stmt before applying this transformation would be
> precisely the kind of check I think we'll want to add to dominator
> optimizer to prevent gratuitous substitutions.
> 

What do you think about the following patch for the tree-ssa branch?
Bootstrapped on i686-pc-linux-gnu.  Testing in progress.

	* Makefile.in (tree-ssa-dom.o): Depends on cfgloop.h.
	* tree-flow-inline.h (loop_of_stmt): New function.
	* tree-ssa-dom.c: Include cfgloop.h.
	(tree_ssa_dominator_optimize): Detect and finalize the natural
	loops structure.
	(simplify_rhs_and_lookup_avail_expr): Verify that the folded
	operations belong to the same loop.  


Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.903.2.172
diff -d -u -p -r1.903.2.172 Makefile.in
--- Makefile.in	28 Jan 2004 09:17:48 -0000	1.903.2.172
+++ Makefile.in	29 Jan 2004 15:35:42 -0000
@@ -1550,7 +1550,7 @@ tree-ssa.o : tree-ssa.c $(TREE_FLOW_H) $
 tree-ssa-dom.o : tree-ssa-dom.c $(TREE_FLOW_H) $(CONFIG_H) $(SYSTEM_H) \
    $(RTL_H) $(TREE_H) $(TM_P_H) $(EXPR_H) $(GGC_H) output.h diagnostic.h \
    errors.h function.h $(TIMEVAR_H) $(TM_H) coretypes.h $(TREE_DUMP_H) \
-   $(BASIC_BLOCK_H) domwalk.h real.h tree-pass.h flags.h
+   $(BASIC_BLOCK_H) domwalk.h real.h tree-pass.h flags.h cfgloop.h
 tree-ssanames.o : tree-ssanames.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
    $(TM_H) $(TREE_H) varray.h $(GGC_H) gt-tree-ssanames.h 
 tree-phinodes.o : tree-phinodes.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
Index: tree-flow-inline.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow-inline.h,v
retrieving revision 1.1.2.65
diff -d -u -p -r1.1.2.65 tree-flow-inline.h
--- tree-flow-inline.h	7 Jan 2004 23:44:15 -0000	1.1.2.65
+++ tree-flow-inline.h	29 Jan 2004 15:35:42 -0000
@@ -563,6 +563,14 @@ bsi_stmt_ptr (block_stmt_iterator i)
   return tsi_stmt_ptr (i.tsi);
 }
 
+/* Returns the loop of the statement STMT.  */
+
+static inline struct loop *
+loop_of_stmt (tree stmt)
+{
+  return bb_for_stmt (stmt)->loop_father;
+}
+
 static inline bool
 may_be_aliased (tree var)
 {
Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dom.c,v
retrieving revision 1.1.2.120
diff -d -u -p -r1.1.2.120 tree-ssa-dom.c
--- tree-ssa-dom.c	21 Jan 2004 21:57:09 -0000	1.1.2.120
+++ tree-ssa-dom.c	29 Jan 2004 15:35:42 -0000
@@ -35,6 +35,7 @@ Boston, MA 02111-1307, USA.  */
 #include "function.h"
 #include "diagnostic.h"
 #include "timevar.h"
+#include "cfgloop.h"
 #include "tree-dump.h"
 #include "tree-flow.h"
 #include "domwalk.h"
@@ -321,6 +322,10 @@ tree_ssa_dominator_optimize (void)
   edge e;
   struct dom_walk_data walk_data;
   tree phi;
+  struct loops* loops;
+
+  /* Compute the natural loops.  */
+  loops = loop_optimizer_init (NULL);
 
   /* Mark loop edges so we avoid threading across loop boundaries.
      This may result in transforming natural loop into irreducible
@@ -580,6 +585,8 @@ tree_ssa_dominator_optimize (void)
   /* Remove any unreachable blocks left behind and linearize the CFG.  */
   cleanup_tree_cfg ();
 
+  loop_optimizer_finalize (loops, NULL);
+
   /* Debugging dumps.  */
   if (tree_dump_file && (tree_dump_flags & TDF_STATS))
     dump_dominator_optimization_stats (tree_dump_file);
@@ -1645,7 +1652,8 @@ simplify_rhs_and_lookup_avail_expr (stru
 
       /* See if the RHS_DEF_STMT has the same form as our statement.  */
       if (TREE_CODE (rhs_def_stmt) == MODIFY_EXPR
-	  && TREE_CODE (TREE_OPERAND (rhs_def_stmt, 1)) == rhs_code)
+	  && TREE_CODE (TREE_OPERAND (rhs_def_stmt, 1)) == rhs_code
+	  && loop_of_stmt (rhs_def_stmt) == loop_of_stmt (stmt))
 	{
 	  tree rhs_def_operand;
 
@@ -1674,7 +1682,8 @@ simplify_rhs_and_lookup_avail_expr (stru
 
       /* See if the RHS_DEF_STMT has the same form as our statement.  */
       if (TREE_CODE (rhs_def_stmt) == MODIFY_EXPR
-	  && TREE_CODE (TREE_OPERAND (rhs_def_stmt, 1)) == rhs_code)
+	  && TREE_CODE (TREE_OPERAND (rhs_def_stmt, 1)) == rhs_code
+	  && loop_of_stmt (rhs_def_stmt) == loop_of_stmt (stmt))
 	{
 	  tree rhs_def_rhs = TREE_OPERAND (rhs_def_stmt, 1);
 	  tree def_stmt_op0 = TREE_OPERAND (rhs_def_rhs, 0);



More information about the Gcc-patches mailing list