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]

Re: [PATCH] Fix PR18754: add early loop pass, 2nd try


On Thu, 20 Jan 2005, Zdenek Dvorak wrote:

> > >The right fix seems to be to add the second SRA pass in the middle of loop
> > >optimizations (just immediately after cunroll).  You would also need to
> > >schedule constant propagation pass there (which should just work)
> > >and preferably also cfg_cleanup (the variation from tcb branch that
> > >preserves loop structures).
> >
> > Yes, I tried this - actually just adding SRA and redphi after cunroll,
> > but this caused verify failures about not the right ssa form or so.  So
> > I guessed SRA may be not ready to preserve invariants the loop
> > optimizers need.
>
> you probably need to rerun the loop closed ssa form creation afterwards
> (rewrite_into_loop_closed_ssa).

Ok, tried this again (see proof of concept patch below).  With
-O2 -funroll-loops this solves the original testcase of PR18754,
but fails on the C++ testcase verifying the ssa form:

scalar_loops.cpp: In function 'void foo(const Array<2>&, const
Array<2>&)':
scalar_loops.cpp:32: internal compiler error: tree check: expected
ssa_name, have var_decl in verify_ssa, at tree-ssa.c:690
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Any ideas what is going wrong?  This doesn't change, if I remove
the rename_ssa_copies() call.

Thanks,
Richard.


Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 2.69
diff -u -c -3 -p -r2.69 tree-optimize.c
*** tree-optimize.c	20 Jan 2005 19:20:24 -0000	2.69
--- tree-optimize.c	21 Jan 2005 12:27:29 -0000
*************** init_tree_optimization_passes (void)
*** 414,419 ****
--- 414,420 ----
    NEXT_PASS (pass_if_conversion);
    NEXT_PASS (pass_vectorize);
    NEXT_PASS (pass_complete_unroll);
+   NEXT_PASS (pass_sra_after_loop);
    NEXT_PASS (pass_iv_optimize);
    NEXT_PASS (pass_loop_done);
    *p = NULL;
Index: tree-pass.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-pass.h,v
retrieving revision 2.25
diff -u -c -3 -p -r2.25 tree-pass.h
*** tree-pass.h	20 Jan 2005 19:20:25 -0000	2.25
--- tree-pass.h	21 Jan 2005 12:27:29 -0000
*************** extern struct tree_opt_pass pass_build_c
*** 122,127 ****
--- 122,128 ----
  extern struct tree_opt_pass pass_tree_profile;
  extern struct tree_opt_pass pass_referenced_vars;
  extern struct tree_opt_pass pass_sra;
+ extern struct tree_opt_pass pass_sra_after_loop;
  extern struct tree_opt_pass pass_tail_recursion;
  extern struct tree_opt_pass pass_tail_calls;
  extern struct tree_opt_pass pass_loop;
Index: tree-sra.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-sra.c,v
retrieving revision 2.50
diff -u -c -3 -p -r2.50 tree-sra.c
*** tree-sra.c	4 Jan 2005 23:54:26 -0000	2.50
--- tree-sra.c	21 Jan 2005 12:27:29 -0000
*************** debug_sra_elt_name (struct sra_elt *elt)
*** 2061,2068 ****
  }

  /* Main entry point.  */
!
! static void
  tree_sra (void)
  {
    /* Initialize local variables.  */
--- 2061,2068 ----
  }

  /* Main entry point.  */
! void tree_sra(void);
! void
  tree_sra (void)
  {
    /* Initialize local variables.  */
Index: tree-ssa-copyrename.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-copyrename.c,v
retrieving revision 2.19
diff -u -c -3 -p -r2.19 tree-ssa-copyrename.c
*** tree-ssa-copyrename.c	6 Nov 2004 19:59:19 -0000	2.19
--- tree-ssa-copyrename.c	21 Jan 2005 12:27:29 -0000
*************** copy_rename_partition_coalesce (var_map
*** 290,297 ****
     changing the underlying root variable of all coalesced version.  This will
     then cause the SSA->normal pass to attempt to coalesce them all to the same
     variable.  */
!
! static void
  rename_ssa_copies (void)
  {
    var_map map;
--- 290,297 ----
     changing the underlying root variable of all coalesced version.  This will
     then cause the SSA->normal pass to attempt to coalesce them all to the same
     variable.  */
! void rename_ssa_copies (void);
! void
  rename_ssa_copies (void)
  {
    var_map map;
Index: tree-ssa-loop-ivcanon.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-ivcanon.c,v
retrieving revision 2.5
diff -u -c -3 -p -r2.5 tree-ssa-loop-ivcanon.c
*** tree-ssa-loop-ivcanon.c	1 Oct 2004 18:26:31 -0000	2.5
--- tree-ssa-loop-ivcanon.c	21 Jan 2005 12:27:29 -0000
*************** tree_num_loop_insns (struct loop *loop)
*** 122,127 ****
--- 122,129 ----
     even if it may cause code growth.  EXIT is the exit of the loop
     that should be eliminated.  */

+ extern int unrolled_loops;
+
  static bool
  try_unroll_loop_completely (struct loops *loops ATTRIBUTE_UNUSED,
  			    struct loop *loop,
*************** try_unroll_loop_completely (struct loops
*** 190,195 ****
--- 192,199 ----
    if (dump_file && (dump_flags & TDF_DETAILS))
      fprintf (dump_file, "Unrolled loop %d completely.\n", loop->num);

+   ++unrolled_loops;
+
    return true;
  }

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	21 Jan 2005 12:27:29 -0000
*************** struct tree_opt_pass pass_record_bounds
*** 328,339 ****
--- 328,343 ----

  /* Complete unrolling of loops.  */

+ int unrolled_loops = 0;
+
  static void
  tree_complete_unroll (void)
  {
    if (!current_loops)
      return;

+   unrolled_loops = 0;
+
    tree_unroll_loops_completely (current_loops);
  }

*************** struct tree_opt_pass pass_complete_unrol
*** 360,365 ****
--- 364,405 ----
    0					/* letter */
  };

+ /* SRA after complete unrolling of loops.  */
+
+ extern void tree_sra(void);
+ extern void rename_ssa_copies(void);
+
+ static void
+ tree_sra_after_loop (void)
+ {
+   tree_sra();
+   rename_ssa_copies();
+   rewrite_into_loop_closed_ssa();
+ }
+
+ static bool
+ gate_sra_after_loop (void)
+ {
+   return flag_tree_sra && unrolled_loops != 0;
+ }
+
+ struct tree_opt_pass pass_sra_after_loop =
+ {
+   "sra",			        /* name */
+   gate_sra_after_loop,		        /* gate */
+   tree_sra_after_loop,		       	/* execute */
+   NULL,					/* sub */
+   NULL,					/* next */
+   0,					/* static_pass_number */
+   TV_TREE_SRA,	  		        /* tv_id */
+   PROP_cfg | PROP_ssa | PROP_alias,	/* properties_required */
+   0,					/* properties_provided */
+   0,					/* properties_destroyed */
+   0,					/* todo_flags_start */
+   TODO_dump_func,                       /* todo_flags_finish */
+   0					/* letter */
+ };
+
  /* Induction variable optimizations.  */

  static void


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