This is the mail archive of the gcc@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]

-funsafe-loop-optimizations


Hello,

several times some people sounded opinion that in addition to improving
analyses in loop optimizer, we might also add a flag that would enable
the compiler to assume that the compiled code does not contain loops
behaving in "weird" way (loops whose control induction variables
overflows, infinite loops with nontrivial exit conditions).

I remember several people were against this possibility.  Therefore
I send the proposal for the patch implementing this flag first here
to the gcc list, to give the chance to discuss about it before I try
to test and submit it properly (or not).

Zdenek

	* common.opt (funsafe-loop-optimizations): New flag.
	* loop-iv.c (iv_number_of_iterations): Assume that no overflow occurs
	if -funsafe-loop-optimizations.
	* tree-ssa-loop-niter.c (number_of_iterations_cond): Ditto.
	* tree-ssa-dce.c (find_obviously_necessary_stmts): Assume that loops
	are not infinite if -funsafe-loop-optimizations.
	* doc/invoke.texi (-funsafe-loop-optimizations): Document.

Index: common.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/common.opt,v
retrieving revision 1.59
diff -c -3 -p -r1.59 common.opt
*** common.opt	28 Oct 2004 03:42:22 -0000	1.59
--- common.opt	31 Dec 2004 20:59:34 -0000
*************** funroll-all-loops
*** 896,901 ****
--- 896,908 ----
  Common Report Var(flag_unroll_all_loops)
  Perform loop unrolling for all loops
  
+ ; Nonzero means that loop optimizer may assume that the induction variables
+ ; that control loops do not overflow and that the loops with nontrivial
+ ; exit condition are not infinite
+ funsafe-loop-optimizations
+ Common Report Var(flag_unsafe_loop_optimizations)
+ Allow loop optimizations to assume that the loops behave in normal way
+ 
  ; Nonzero means that unsafe floating-point math optimizations are allowed
  ; for the sake of speed.  IEEE compliance is not guaranteed, and operations
  ; are allowed to assume that their arguments and results are "normal"
Index: loop-iv.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/loop-iv.c,v
retrieving revision 2.26
diff -c -3 -p -r2.26 loop-iv.c
*** loop-iv.c	28 Dec 2004 10:33:39 -0000	2.26
--- loop-iv.c	31 Dec 2004 20:59:34 -0000
*************** iv_number_of_iterations (struct loop *lo
*** 2534,2539 ****
--- 2534,2546 ----
        desc->niter_expr = old_niter;
      }
  
+   if (flag_unsafe_loop_optimizations)
+     {
+       /* Assume that no overflow happens and that the loop is finite.  */
+       desc->assumptions = NULL_RTX;
+       desc->infinite = NULL_RTX;
+     }
+ 
    return;
  
  fail:
Index: tree-ssa-dce.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-dce.c,v
retrieving revision 2.29
diff -c -3 -p -r2.29 tree-ssa-dce.c
*** tree-ssa-dce.c	13 Dec 2004 16:03:40 -0000	2.29
--- tree-ssa-dce.c	31 Dec 2004 20:59:34 -0000
*************** find_obviously_necessary_stmts (struct e
*** 489,498 ****
        bb->flags &= ~BB_VISITED;
      }
  
!   if (el)
      {
        /* Prevent the loops from being removed.  We must keep the infinite loops,
! 	 and we currently do not have a means to recognize the finite ones.  */
        FOR_EACH_BB (bb)
  	{
  	  edge_iterator ei;
--- 489,501 ----
        bb->flags &= ~BB_VISITED;
      }
  
!   if (el && !flag_unsafe_loop_optimizations)
      {
        /* Prevent the loops from being removed.  We must keep the infinite loops,
! 	 and we currently do not have a means to recognize the finite ones.
! 	 
! 	 With -funsafe-loop-optimizations we assume that the loops are not
! 	 infinite.  */
        FOR_EACH_BB (bb)
  	{
  	  edge_iterator ei;
Index: tree-ssa-loop-niter.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-niter.c,v
retrieving revision 2.18
diff -c -3 -p -r2.18 tree-ssa-loop-niter.c
*** tree-ssa-loop-niter.c	23 Nov 2004 01:27:42 -0000	2.18
--- tree-ssa-loop-niter.c	31 Dec 2004 20:59:34 -0000
*************** number_of_iterations_cond (tree type, tr
*** 489,495 ****
        niter->niter = delta;
      }
  
!   niter->assumptions = assumptions;
    niter->may_be_zero = noloop_assumptions;
    return;
  
--- 489,503 ----
        niter->niter = delta;
      }
  
!   if (flag_unsafe_loop_optimizations)
!     {
!       /* With -funsafe-loop-optimizations we assume that nothing bad can
! 	 happen.  */
!       niter->assumptions = boolean_true_node;
!     }
!   else
!     niter->assumptions = assumptions;
! 
    niter->may_be_zero = noloop_assumptions;
    return;
  
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.563
diff -c -3 -p -r1.563 invoke.texi
*** doc/invoke.texi	28 Dec 2004 04:24:30 -0000	1.563
--- doc/invoke.texi	31 Dec 2004 20:59:35 -0000
*************** Objective-C and Objective-C++ Dialects}.
*** 298,304 ****
  -fno-default-inline  -fno-defer-pop -floop-optimize2 -fmove-loop-invariants @gol
  -fno-function-cse  -fno-guess-branch-probability @gol
  -fno-inline  -fno-math-errno  -fno-peephole  -fno-peephole2 @gol
! -funsafe-math-optimizations  -ffinite-math-only @gol
  -fno-trapping-math  -fno-zero-initialized-in-bss @gol
  -fomit-frame-pointer  -foptimize-register-move @gol
  -foptimize-sibling-calls  -fprefetch-loop-arrays @gol
--- 298,304 ----
  -fno-default-inline  -fno-defer-pop -floop-optimize2 -fmove-loop-invariants @gol
  -fno-function-cse  -fno-guess-branch-probability @gol
  -fno-inline  -fno-math-errno  -fno-peephole  -fno-peephole2 @gol
! -funsafe-math-optimizations  -funsafe-loop-optimizations  -ffinite-math-only @gol
  -fno-trapping-math  -fno-zero-initialized-in-bss @gol
  -fomit-frame-pointer  -foptimize-register-move @gol
  -foptimize-sibling-calls  -fprefetch-loop-arrays @gol
*************** Perform loop optimizations using the new
*** 4464,4469 ****
--- 4464,4477 ----
  (loop unrolling, peeling and unswitching, loop invariant motion) are enabled
  by separate flags.
  
+ @item -funsafe-loop-optimizations
+ @opindex funsafe-loop-optimizations
+ Nonzero means that loop optimizer may assume that the induction variables
+ that control loops do not overflow and that the loops with nontrivial
+ exit condition are not infinite.  This enables wider range of loop
+ optimizations even in the case loop optimizer itself is unable to disprove
+ that some of these improbable events happen.
+ 
  @item -fcrossjumping
  @opindex crossjumping
  Perform cross-jumping transformation.  This transformation unifies equivalent code and save code size.  The


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