[patch] Enable ivcanon & complete loop unrolling

Zdenek Dvorak rakdver@atrey.karlin.mff.cuni.cz
Fri Sep 24 20:44:00 GMT 2004


Hello,

now that the tree level loop unrolling functions were merged, it is
possible to perform complete loop unrolling on tree level.

Also it is possible to enable ivcanon by default, since ivopts will
remove the newly created induction variable if it is not useful.

Bootstrapped (with -funroll-loops) & regtested on i686.  To bootstrap
a fix for PR 17474 (not included in the patch) is necessary.

Zdenek

	* common.opt (ftree-loop-ivcanon): Enable by default.
	* tree-ssa-loop-ivcanon.c (try_unroll_loop_completely):
	Enable complete loop unrolling.
	(canonicalize_induction_variables, tree_unroll_loops_completely):
	Reset scev info.

	* gcc.dg/tree-ssa/loop-1.c: Check that unrolling occurs already on
	tree level.

Index: common.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/common.opt,v
retrieving revision 1.55
diff -c -3 -p -r1.55 common.opt
*** common.opt	14 Sep 2004 08:05:45 -0000	1.55
--- common.opt	24 Sep 2004 08:50:40 -0000
*************** Common Report Var(flag_tree_loop_linear)
*** 857,863 ****
  Enable linear loop transforms on trees
  
  ftree-loop-ivcanon
! Common Report Var(flag_tree_loop_ivcanon)
  Create canonical induction variables in loops
  
  ftree-loop-optimize
--- 857,863 ----
  Enable linear loop transforms on trees
  
  ftree-loop-ivcanon
! Common Report Var(flag_tree_loop_ivcanon) Init(1)
  Create canonical induction variables in loops
  
  ftree-loop-optimize
Index: tree-ssa-loop-ivcanon.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-ivcanon.c,v
retrieving revision 2.3
diff -c -3 -p -r2.3 tree-ssa-loop-ivcanon.c
*** tree-ssa-loop-ivcanon.c	3 Sep 2004 02:19:37 -0000	2.3
--- tree-ssa-loop-ivcanon.c	24 Sep 2004 08:50:40 -0000
*************** try_unroll_loop_completely (struct loops
*** 175,186 ****
        COND_EXPR_COND (cond) = dont_exit;
        modify_stmt (cond);
  
- #if 0
-       /* The necessary infrastructure is not in yet.  */
        if (!tree_duplicate_loop_to_header_edge (loop, loop_preheader_edge (loop),
  					       loops, n_unroll, NULL,
  					       NULL, NULL, NULL, 0))
- #endif
  	{
  	  COND_EXPR_COND (cond) = old_cond;
  	  return false;
--- 175,183 ----
*************** canonicalize_induction_variables (struct
*** 263,268 ****
--- 260,269 ----
  	canonicalize_loop_induction_variables (loops, loop, true, false, true);
      }
  
+   /* Clean up the information about numbers of iterations, since brute force
+      evaluation could reveal new information.  */
+   scev_reset ();
+ 
  #if 0
    /* The necessary infrastructure is not in yet.  */
    if (changed)
*************** tree_unroll_loops_completely (struct loo
*** 291,296 ****
--- 292,301 ----
  							!flag_tree_loop_ivcanon);
      }
  
+   /* Clean up the information about numbers of iterations, since complete
+      unrolling might have invalidated it.  */
+   scev_reset ();
+ 
  #if 0
    /* The necessary infrastructure is not in yet.  */
    if (changed)
Index: testsuite/gcc.dg/tree-ssa/loop-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/tree-ssa/loop-1.c,v
retrieving revision 1.2
diff -c -3 -p -r1.2 loop-1.c
*** testsuite/gcc.dg/tree-ssa/loop-1.c	3 Sep 2004 13:53:22 -0000	1.2
--- testsuite/gcc.dg/tree-ssa/loop-1.c	24 Sep 2004 08:50:42 -0000
***************
*** 1,5 ****
  /* { dg-do compile } */
! /* { dg-options "-O1 -ftree-loop-ivcanon -funroll-loops -fdump-tree-ivcanon-details" } */
  
  void xxx(void)
  {
--- 1,5 ----
  /* { dg-do compile } */
! /* { dg-options "-O1 -ftree-loop-ivcanon -funroll-loops -fdump-tree-ivcanon-details -fdump-tree-cunroll-details -fdump-tree-vars" } */
  
  void xxx(void)
  {
*************** void xxx(void)
*** 12,17 ****
--- 12,19 ----
  /* We should be able to find out that the loop iterates four times and unroll it completely.  */
  
  /* { dg-final { scan-tree-dump-times "Added canonical iv to loop 1, 4 iterations" 1 "ivcanon"} } */
+ /* { dg-final { scan-tree-dump-times "Unrolled loop 1 completely" 1 "cunroll"} } */
+ /* { dg-final { scan-tree-dump-times "foo" 5 "vars"} } */
  /* { dg-final { scan-assembler-times "foo" 5} } */
  
  



More information about the Gcc-patches mailing list