public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][RFC] Add -fno-aggressive-loop-optimizations
@ 2013-01-29 10:53 Richard Biener
  2013-01-30 17:26 ` Pat Haugen
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Biener @ 2013-01-29 10:53 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek, hjl.tools


The following patch adds -faggressive-loop-optimizations, enabled by
default, guarding the use of language constraints for number of
iteration analysis.  Starting with GCC 4.8 we more aggressively
make use of iteration bounds derived from those constraints
which for example breaks SPEC CPU 2006 464.h264ref which is
not C99 conforming but SPEC folks think it is not in the spirit
of theirs to fix such issues (but we compiler folks have to deal
with that - where the language standard interpretation would
be to DWIM, thus let SPEC pass).

Thus, GCC 4.8 will need -fno-aggressive-loop-optimizations in
base flags to compile official SPEC CPU 2006 sources (as opposed
to local patched ones).  I suppose I'll add a sentence to
changes.html reflecting that fact.

Note that using this flag will disable using of language constraints
of this kind from number-of-iteration analysis completely
(mind, that's not previous behavior - previous behavior just used
the resulting information in less places).  It places it in the
same ballpark as -fno-strict-aliasing and -fno-strict-overflow.
Thus, no guarantees - it does not make out-of-bound array accesses
in any way more valid - your broken code may still be optimized
in unexpected ways.  It just disables one source of "unexpectedness".
No testcase added for that reason.

Thus, any objections to providing this switch guarding an
implementation detail of number of iteration analysis?

I'm curious about the affect of -fno-aggressive-loop-optimizations
on SPEC CPU 2006 numbers (not curious enough to try for myself
though).  Both on extra PASSes for official latest sources
(I have no access to those) and on performance.

Thanks,
Richard.

2013-01-29  Richard Biener  <rguenther@suse.de>

	PR middle-end/53073
	* common.opt (faggressive-loop-optimizations): New flag,
	enabled by default.
	* doc/invoke.texi (faggressive-loop-optimizations): Document.
	* tree-ssa-loop-niter.c (estimate_numbers_of_iterations_loop): Guard
	infer_loop_bounds_from_undefined by it.

Index: gcc/common.opt
===================================================================
*** gcc/common.opt	(revision 195530)
--- gcc/common.opt	(working copy)
*************** Driver Undocumented
*** 792,797 ****
--- 792,801 ----
  fabi-version=
  Common Joined RejectNegative UInteger Var(flag_abi_version) Init(2)
  
+ faggressive-loop-optimizations
+ Common Report Var(flag_aggressive_loop_optimizations) Optimization Init(1) 
+ Aggressively optimize loops using language constraints
+ 
  falign-functions
  Common Report Var(align_functions,0) Optimization UInteger
  Align the start of functions
Index: gcc/doc/invoke.texi
===================================================================
*** gcc/doc/invoke.texi	(revision 195530)
--- gcc/doc/invoke.texi	(working copy)
*************** Objective-C and Objective-C++ Dialects}.
*** 349,355 ****
  
  @item Optimization Options
  @xref{Optimize Options,,Options that Control Optimization}.
! @gccoptlist{-falign-functions[=@var{n}] -falign-jumps[=@var{n}] @gol
  -falign-labels[=@var{n}] -falign-loops[=@var{n}] @gol
  -fassociative-math -fauto-inc-dec -fbranch-probabilities @gol
  -fbranch-target-load-optimize -fbranch-target-load-optimize2 @gol
--- 349,356 ----
  
  @item Optimization Options
  @xref{Optimize Options,,Options that Control Optimization}.
! @gccoptlist{-faggressive-loop-optimizations -falign-functions[=@var{n}] @gol
! -falign-jumps[=@var{n}] @gol
  -falign-labels[=@var{n}] -falign-loops[=@var{n}] @gol
  -fassociative-math -fauto-inc-dec -fbranch-probabilities @gol
  -fbranch-target-load-optimize -fbranch-target-load-optimize2 @gol
*************** When @option{-fgcse-after-reload} is ena
*** 6988,6993 ****
--- 6989,7004 ----
  pass is performed after reload.  The purpose of this pass is to clean up
  redundant spilling.
  
+ @item -faggressive-loop-optimizations
+ @opindex faggressive-loop-optimizations
+ This option tells the loop optimizer to use language constraints to
+ derive bounds for the number of iterations of a loop.  This assumes that
+ loop code does not invoke undefined behavior by for example causing signed
+ integer overflows or out-of-bound array accesses.  The bounds for the
+ number of iterations of a loop are used to guide loop unrolling and peeling
+ and loop exit test optimizations.
+ This option is enabled by default.
+ 
  @item -funsafe-loop-optimizations
  @opindex funsafe-loop-optimizations
  This option tells the loop optimizer to assume that loop indices do not
Index: gcc/tree-ssa-loop-niter.c
===================================================================
*** gcc/tree-ssa-loop-niter.c	(revision 195530)
--- gcc/tree-ssa-loop-niter.c	(working copy)
*************** estimate_numbers_of_iterations_loop (str
*** 3336,3342 ****
      }
    exits.release ();
  
!   infer_loop_bounds_from_undefined (loop);
  
    discover_iteration_bound_by_body_walk (loop);
  
--- 3336,3343 ----
      }
    exits.release ();
  
!   if (flag_aggressive_loop_optimizations)
!     infer_loop_bounds_from_undefined (loop);
  
    discover_iteration_bound_by_body_walk (loop);
  

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [PATCH][RFC] Add -fno-aggressive-loop-optimizations
@ 2013-01-30 16:48 Dominique Dhumieres
  0 siblings, 0 replies; 7+ messages in thread
From: Dominique Dhumieres @ 2013-01-30 16:48 UTC (permalink / raw)
  To: gcc-patches; +Cc: jakub, jh, rguenther

I just finished a clean bootstrap of r195576 with your patch.
I have used it to clean the XPASS of gfortran.dg/do_1.f90 for -O0
and -O1 with the following patch:

--- /opt/gcc/_clean/gcc/testsuite/gfortran.dg/do_1.f90	2012-10-18 20:35:25.000000000 +0200
+++ /opt/gcc/work/gcc/testsuite/gfortran.dg/do_1.f90	2013-01-30 17:00:30.000000000 +0100
@@ -1,4 +1,5 @@
-! { dg-do run { xfail *-*-* } }
+! { dg-do run }
+! { dg-additional-options "-fno-aggressive-loop-optimizations" }
 ! XFAIL is tracked in PR 54932
 ! Program to check corner cases for DO statements.
 program do_1

Cheers,

Dominique

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-02-18  9:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-29 10:53 [PATCH][RFC] Add -fno-aggressive-loop-optimizations Richard Biener
2013-01-30 17:26 ` Pat Haugen
2013-01-31  9:06   ` Richard Biener
2013-01-31  9:11     ` Richard Biener
2013-02-16 23:43       ` Gerald Pfeifer
2013-02-18  9:10         ` Richard Biener
2013-01-30 16:48 Dominique Dhumieres

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).