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 PR18754: add early loop pass


Hi!

This patch adds an early loop pass (just after ch) just
containing complete unrolling.  This allows the following
SRA pass to scalarize small arrays that were manipulated
in constant rolling loops, as it often happens in C++ code.

I did experiments with scheduling a second SRA pass after
loop optimization, but that doesn't help ivopts - we'd need
another loop pass after the second SRA this way.  I also
tried scheduling SRA inside loop, just after cunroll, but
SRA seems to not preserve some of the loop infrastructure,
so everyting breaks.

Getting rid of the (artificial) constant rolling loops early
seemed to be the best.  Note that it is important to schedule
a dom pass inbetween cunroll and sra (redundant_phi is not
strictly necessary, but is run everywhere where dom is run,
so ...).  Scheduling the early loop even earlier before the
first dom didn't work out either.

Together with Zdeneks patch for complete unrolling without
-funroll-loops, this optimizes PR18754 quite well at -O2
(see the bug for asm dumps).

Bootstrapped on ia32.

What do you think?

Richard.


2005-Jan-20  Richard Guenther <richard.guenther@uni-tuebingen.de>

	* tree-optimize.c (init_tree_optimization_passes):
	schedule loop0, dom and redphi after between ch and sra.
	tree-pass.h: declare pass_loop0.
	tree-ssa-loop.c: define pass_loop0,
	(gate_loop0): new.

Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 2.68
diff -u -c -3 -p -r2.68 tree-optimize.c
*** tree-optimize.c	18 Jan 2005 11:36:24 -0000	2.68
--- tree-optimize.c	20 Jan 2005 10:59:29 -0000
*************** init_tree_optimization_passes (void)
*** 359,364 ****
--- 359,367 ----
    NEXT_PASS (pass_may_alias);
    NEXT_PASS (pass_tail_recursion);
    NEXT_PASS (pass_ch);
+   NEXT_PASS (pass_loop0);
+   NEXT_PASS (pass_dominator);
+   NEXT_PASS (pass_redundant_phi);
    NEXT_PASS (pass_profile);
    NEXT_PASS (pass_sra);
    NEXT_PASS (pass_rename_ssa_copies);
*************** init_tree_optimization_passes (void)
*** 403,408 ****
--- 406,417 ----
    NEXT_PASS (pass_cleanup_cfg_post_optimizing);
    *p = NULL;

+   p = &pass_loop0.sub;
+   NEXT_PASS (pass_loop_init);
+   NEXT_PASS (pass_complete_unroll);
+   NEXT_PASS (pass_loop_done);
+   *p = NULL;
+
    p = &pass_loop.sub;
    NEXT_PASS (pass_loop_init);
    NEXT_PASS (pass_lim);
Index: tree-pass.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-pass.h,v
retrieving revision 2.24
diff -u -c -3 -p -r2.24 tree-pass.h
*** tree-pass.h	18 Jan 2005 11:36:26 -0000	2.24
--- tree-pass.h	20 Jan 2005 10:59:29 -0000
*************** extern struct tree_opt_pass pass_referen
*** 124,129 ****
--- 124,130 ----
  extern struct tree_opt_pass pass_sra;
  extern struct tree_opt_pass pass_tail_recursion;
  extern struct tree_opt_pass pass_tail_calls;
+ extern struct tree_opt_pass pass_loop0;
  extern struct tree_opt_pass pass_loop;
  extern struct tree_opt_pass pass_loop_init;
  extern struct tree_opt_pass pass_lim;
Index: tree-ssa-loop.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop.c,v
retrieving revision 2.23
diff -u -c -3 -p -r2.23 tree-ssa-loop.c
*** tree-ssa-loop.c	26 Nov 2004 06:42:25 -0000	2.23
--- tree-ssa-loop.c	20 Jan 2005 10:59:29 -0000
*************** tree_loop_optimizer_init (FILE *dump)
*** 68,73 ****
--- 68,98 ----
    return loops;
  }

+ /* The loop0 superpass.  */
+
+ static bool
+ gate_loop0 (void)
+ {
+   return flag_tree_loop_optimize != 0;
+ }
+
+ struct tree_opt_pass pass_loop0 =
+ {
+   "loop",				/* name */
+   gate_loop0,				/* gate */
+   NULL,					/* execute */
+   NULL,					/* sub */
+   NULL,					/* next */
+   0,					/* static_pass_number */
+   TV_TREE_LOOP,				/* tv_id */
+   PROP_cfg,				/* properties_required */
+   0,					/* properties_provided */
+   0,					/* properties_destroyed */
+   TODO_ggc_collect,			/* todo_flags_start */
+   TODO_dump_func | TODO_verify_ssa | TODO_ggc_collect,	/* todo_flags_finish */
+   0					/* letter */
+ };
+
  /* The loop superpass.  */

  static bool



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