This patch adds an option called -O1g, a half-way house between
-Og and -O1 in terms of both performance and debuggability.


2019-06-23  Richard Sandiford  <richard.sandif...@arm.com>

config/
        * bootstrap-O1g.mk: New file.

gcc/
        * common.opt (O1g): New option.
        * doc/invoke.texi: Document it.
        * opts.c (default_options_optimization): Handle it.
        (common_handle_option): Likewise.

gcc/testsuite/
        * g++.dg/guality/guality.exp: Add "-O1g -g" to the list of options
        to try for Og-* tests.
        * gcc.dg/guality/guality.exp: Likewise.
        * gcc.dg/sso/sso.exp (SSO_TORTURE_OPTIONS): Add "-O1g -g".
        * gnat.dg/sso/sso.exp (SSO_TORTURE_OPTIONS): Likewise.
        * lib/c-torture.exp (TORTURE_OPTIONS): Likewise.

Index: config/bootstrap-O1g.mk
===================================================================
--- /dev/null   2019-06-14 15:59:19.298479944 +0100
+++ config/bootstrap-O1g.mk     2019-06-23 14:48:59.302941670 +0100
@@ -0,0 +1,1 @@
+BOOT_CFLAGS := -O1g $(filter-out -O%, $(BOOT_CFLAGS))
Index: gcc/common.opt
===================================================================
--- gcc/common.opt      2019-06-23 14:48:44.495065059 +0100
+++ gcc/common.opt      2019-06-23 14:48:59.302941670 +0100
@@ -487,6 +487,9 @@ Og
 Common Optimization
 Optimize for debugging experience rather than speed or size.
 
+O1g
+Common Optimization
+
 Q
 Driver
 
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi 2019-06-18 09:35:52.089892867 +0100
+++ gcc/doc/invoke.texi 2019-06-23 14:48:59.314941570 +0100
@@ -8403,6 +8403,19 @@ optimization flags except for those that
 -fmove-loop-invariants  -fssa-phiopt @gol
 -ftree-bit-ccp  -ftree-pta  -ftree-sra}
 
+@item -O1g
+@opindex O1g
+Perform the same optimizations as @option{-O1}, but take the debug
+experience into consideration when optimizing.  In particular, try to
+make sure that the values of simple variables are printable at any
+point during their scope.
+
+This option is a compromise between @option{-Og} and @option{-O1}.
+The code it produces is generally faster than the code that
+@option{-Og} produces, but not as fast as the code that @option{-O1}
+produces.  In contrast, the code that @option{-O1g} produces should be
+easier to debug than code that @option{-O1} produces, but might not be
+as easy to debug as the code that @option{-Og} produces.
 @end table
 
 If you use multiple @option{-O} options, with or without level numbers,
Index: gcc/opts.c
===================================================================
--- gcc/opts.c  2019-06-23 14:48:44.507064959 +0100
+++ gcc/opts.c  2019-06-23 14:48:59.314941570 +0100
@@ -639,6 +639,14 @@ default_options_optimization (struct gcc
          opts->x_flag_tangible_debug = 1;
          break;
 
+       case OPT_O1g:
+         opts->x_optimize_size = 0;
+         opts->x_optimize = 1;
+         opts->x_optimize_fast = 0;
+         opts->x_optimize_debug = 0;
+         opts->x_flag_tangible_debug = 1;
+         break;
+
        case OPT_fopenacc:
          if (opt->value)
            openacc_mode = true;
@@ -2323,6 +2331,7 @@ common_handle_option (struct gcc_options
     case OPT_Os:
     case OPT_Ofast:
     case OPT_Og:
+    case OPT_O1g:
       /* Currently handled in a prescan.  */
       break;
 
Index: gcc/testsuite/g++.dg/guality/guality.exp
===================================================================
--- gcc/testsuite/g++.dg/guality/guality.exp    2019-06-23 14:48:44.511064925 
+0100
+++ gcc/testsuite/g++.dg/guality/guality.exp    2019-06-23 14:48:59.314941570 
+0100
@@ -78,9 +78,9 @@ if {[check_guality "
     gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.C]] "" ""
     gcc-dg-runtest $general "" ""
     set-torture-options \
-      [list "-O0" "-Og"] \
+      [list "-O0" "-Og" "-O1g"] \
       [list {}] \
-      [list "-Og -flto"]
+      [list "-Og -flto" "-O1g -flto"]
     gcc-dg-runtest $Og "" ""
 }
 
Index: gcc/testsuite/gcc.dg/guality/guality.exp
===================================================================
--- gcc/testsuite/gcc.dg/guality/guality.exp    2019-06-23 14:48:44.511064925 
+0100
+++ gcc/testsuite/gcc.dg/guality/guality.exp    2019-06-23 14:48:59.314941570 
+0100
@@ -93,9 +93,9 @@ if {[check_guality "
     gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] "" ""
     gcc-dg-runtest $general "" "-Wc++-compat"
     set-torture-options \
-      [list "-O0" "-Og"] \
+      [list "-O0" "-Og" "-O1g"] \
       [list {}] \
-      [list "-Og -flto"]
+      [list "-Og -flto" "-O1g -flto"]
     gcc-dg-runtest $Og "" "-Wc++-compat"
 }
 
Index: gcc/testsuite/gcc.dg/sso/sso.exp
===================================================================
--- gcc/testsuite/gcc.dg/sso/sso.exp    2019-03-08 18:15:04.412863081 +0000
+++ gcc/testsuite/gcc.dg/sso/sso.exp    2019-06-23 14:48:59.314941570 +0100
@@ -32,7 +32,8 @@ set SSO_TORTURE_OPTIONS [list \
        { -O2 } \
        { -O3 -finline-functions } \
        { -Os } \
-       { -Og -g } ]
+       { -Og -g } \
+       { -O1g -g } ]
 
 set-torture-options $SSO_TORTURE_OPTIONS
 
Index: gcc/testsuite/gnat.dg/sso/sso.exp
===================================================================
--- gcc/testsuite/gnat.dg/sso/sso.exp   2019-03-08 18:14:54.692900030 +0000
+++ gcc/testsuite/gnat.dg/sso/sso.exp   2019-06-23 14:48:59.314941570 +0100
@@ -28,7 +28,8 @@ set SSO_TORTURE_OPTIONS [list \
        { -O2 } \
        { -O3 -finline-functions } \
        { -Os } \
-       { -Og -g } ]
+       { -Og -g } \
+       { -O1g -g } ]
 
 set-torture-options $SSO_TORTURE_OPTIONS
 
Index: gcc/testsuite/lib/c-torture.exp
===================================================================
--- gcc/testsuite/lib/c-torture.exp     2019-03-08 18:14:42.504946361 +0000
+++ gcc/testsuite/lib/c-torture.exp     2019-06-23 14:48:59.314941570 +0100
@@ -56,7 +56,8 @@ if [info exists TORTURE_OPTIONS] {
        { -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer 
-finline-functions } \
        { -O3 -g } \
        { -Os } \
-       { -Og -g } ]
+       { -Og -g } \
+       { -O1g -g } ]
 
     if [check_effective_target_lto] {
         # When having plugin test both slim and fat LTO and plugin/nonplugin

Reply via email to