[doc,committed] improve documentation for -Og

Message ID 3ac83285-3e80-701f-e499-d21d2454106d@codesourcery.com
State New
Headers show
Series
  • [doc,committed] improve documentation for -Og
Related show

Commit Message

Sandra Loosemore Nov. 14, 2018, 8:18 p.m.
This patch is for PR 59658, "Document -f* flags enabled by -Og".  As 
noted in the issue comments, this is tricky because -Og uses a separate 
pass list than the other -O levels, and like -O0 it completely ignores 
-f* options for many optimization passes.  And, like -O0, there's really 
nothing in the code to identify which flags are ignored without checking 
them individually against the pass list.  I opened PR 88024 to improve 
the code in that area.  Meanwhile this documentation patch identifies 
the flags that are explicitly defaulted to off and documents that other 
flags are ignored, consistently with how the manual documents the 
similar -O0 abbreviated-passlist behavior.

I have also included a code patch here to better sort the 
default_options_table array in opts.c so it is easier to keep the 
documentation in sync with it.  I think that counts as "obvious" so I 
have gone ahead and committed this patch.

-Sandra

Patch

Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 266082)
+++ gcc/doc/invoke.texi	(working copy)
@@ -7896,9 +7896,10 @@  each of them.
 Not all optimizations are controlled directly by a flag.  Only
 optimizations that have a flag are listed in this section.
 
-Most optimizations are only enabled if an @option{-O} level is set on
-the command line.  Otherwise they are disabled, even if individual
-optimization flags are specified.
+Most optimizations are completely disabled at @option{-O0} or if an
+@option{-O} level is not set on the command line, even if individual
+optimization flags are specified.  Similarly, @option{-Og} suppresses
+many optimization passes.
 
 Depending on the target and how GCC was configured, a slightly different
 set of optimizations may be enabled at each @option{-O} level than
@@ -7918,9 +7919,14 @@  With @option{-O}, the compiler tries to
 time, without performing any optimizations that take a great deal of
 compilation time.
 
+@c Note that in addition to the default_options_table list in opts.c,
+@c several optimization flags default to true but control optimization
+@c passes that are explicitly disabled at -O0.
+
 @option{-O} turns on the following optimization flags:
-@gccoptlist{
--fauto-inc-dec @gol
+
+@c Please keep the following list alphabetized.
+@gccoptlist{-fauto-inc-dec @gol
 -fbranch-count-reg @gol
 -fcombine-stack-adjustments @gol
 -fcompare-elim @gol
@@ -7931,11 +7937,11 @@  compilation time.
 -fdse @gol
 -fforward-propagate @gol
 -fguess-branch-probability @gol
--fif-conversion2 @gol
 -fif-conversion @gol
+-fif-conversion2 @gol
 -finline-functions-called-once @gol
--fipa-pure-const @gol
 -fipa-profile @gol
+-fipa-pure-const @gol
 -fipa-reference @gol
 -fipa-reference-addressable @gol
 -fmerge-constants @gol
@@ -7958,11 +7964,11 @@  compilation time.
 -ftree-forwprop @gol
 -ftree-fre @gol
 -ftree-phiprop @gol
+-ftree-pta @gol
 -ftree-scev-cprop @gol
 -ftree-sink @gol
 -ftree-slsr @gol
 -ftree-sra @gol
--ftree-pta @gol
 -ftree-ter @gol
 -funit-at-a-time}
 
@@ -7975,10 +7981,12 @@  and the performance of the generated cod
 
 @option{-O2} turns on all optimization flags specified by @option{-O}.  It
 also turns on the following optimization flags:
-@gccoptlist{-fthread-jumps @gol
--falign-functions  -falign-jumps @gol
--falign-loops  -falign-labels @gol
+
+@c Please keep the following list alphabetized!
+@gccoptlist{-falign-functions  -falign-jumps @gol
+-falign-labels  -falign-loops @gol
 -fcaller-saves @gol
+-fcode-hoisting @gol
 -fcrossjumping @gol
 -fcse-follow-jumps  -fcse-skip-blocks @gol
 -fdelete-null-pointer-checks @gol
@@ -7988,11 +7996,8 @@  also turns on the following optimization
 -fhoist-adjacent-loads @gol
 -finline-small-functions @gol
 -findirect-inlining @gol
--fipa-cp @gol
--fipa-bit-cp @gol
--fipa-vrp @gol
--fipa-sra @gol
--fipa-icf @gol
+-fipa-bit-cp  -fipa-cp  -fipa-icf @gol
+-fipa-ra  -fipa-sra  -fipa-vrp @gol
 -fisolate-erroneous-paths-dereference @gol
 -flra-remat @gol
 -foptimize-sibling-calls @gol
@@ -8002,16 +8007,15 @@  also turns on the following optimization
 -freorder-blocks-algorithm=stc @gol
 -freorder-blocks-and-partition -freorder-functions @gol
 -frerun-cse-after-loop  @gol
--fsched-interblock  -fsched-spec @gol
 -fschedule-insns  -fschedule-insns2 @gol
+-fsched-interblock  -fsched-spec @gol
 -fstore-merging @gol
 -fstrict-aliasing @gol
+-fthread-jumps @gol
 -ftree-builtin-call-dce @gol
--ftree-switch-conversion -ftree-tail-merge @gol
--fcode-hoisting @gol
 -ftree-pre @gol
--ftree-vrp @gol
--fipa-ra}
+-ftree-switch-conversion -ftree-tail-merge @gol
+-ftree-vrp}
 
 Please note the warning under @option{-fgcse} about
 invoking @option{-O2} on programs that use computed gotos.
@@ -8020,21 +8024,23 @@  invoking @option{-O2} on programs that u
 @opindex O3
 Optimize yet more.  @option{-O3} turns on all optimizations specified
 by @option{-O2} and also turns on the following optimization flags:
-@gccoptlist{-finline-functions @gol
--funswitch-loops @gol
--fpredictive-commoning @gol
--fgcse-after-reload @gol
--ftree-loop-vectorize @gol
--ftree-loop-distribution @gol
--ftree-loop-distribute-patterns @gol
+
+@c Please keep the following list alphabetized!
+@gccoptlist{-fgcse-after-reload @gol
+-finline-functions @gol
+-fipa-cp-clone
 -floop-interchange @gol
 -floop-unroll-and-jam @gol
+-fpeel-loops @gol
+-fpredictive-commoning @gol
 -fsplit-paths @gol
--ftree-slp-vectorize @gol
--fvect-cost-model @gol
+-ftree-loop-distribute-patterns @gol
+-ftree-loop-distribution @gol
+-ftree-loop-vectorize @gol
 -ftree-partial-pre @gol
--fpeel-loops @gol
--fipa-cp-clone}
+-ftree-slp-vectorize @gol
+-funswitch-loops @gol
+-fvect-cost-model}
 
 @item -O0
 @opindex O0
@@ -8043,13 +8049,16 @@  results.  This is the default.
 
 @item -Os
 @opindex Os
-Optimize for size.  @option{-Os} enables all @option{-O2} optimizations that
-do not typically increase code size.  It also performs further
-optimizations designed to reduce code size.
-
-@option{-Os} disables the following optimization flags:
-@gccoptlist{-falign-functions  -falign-jumps  -falign-loops @gol
--falign-labels  -fprefetch-loop-arrays}
+Optimize for size.  @option{-Os} enables all @option{-O2} optimizations 
+except those that often increase code size:
+
+@gccoptlist{-falign-functions  -falign-jumps @gol
+-falign-labels  -falign-loops @gol
+-fprefetch-loop-arrays  -freorder-blocks-algorithm=stc}
+
+It also enables @option{-finline-functions}, causes the compiler to tune for
+code size rather than execution speed, and performs further optimizations
+designed to reduce code size.  
 
 @item -Ofast
 @opindex Ofast
@@ -8062,11 +8071,24 @@  specified, and @option{-fno-protect-pare
 
 @item -Og
 @opindex Og
-Optimize debugging experience.  @option{-Og} enables optimizations
-that do not interfere with debugging. It should be the optimization
+Optimize debugging experience.  @option{-Og} should be the optimization
 level of choice for the standard edit-compile-debug cycle, offering
 a reasonable level of optimization while maintaining fast compilation
-and a good debugging experience.
+and a good debugging experience.  It is a better choice than @option{-O0}
+for producing debuggable code because some compiler passes
+that collect debug information are disabled at @option{-O0}.
+
+Like @option{-O0}, @option{-Og} completely disables a number of 
+optimization passes so that individual options controlling them have
+no effect.  Otherwise @option{-Og} enables all @option{-O1} 
+optimization flags except for those that may interfere with debugging:
+
+@gccoptlist{-fbranch-count-reg  -fdelayed-branch @gol
+-fif-conversion  -fif-conversion2  @gol
+-finline-functions-called-once @gol
+-fmove-loop-invariants  -fssa-phiopt @gol
+-ftree-bit-ccp  -ftree-pta  -ftree-sra}
+
 @end table
 
 If you use multiple @option{-O} options, with or without level numbers,
@@ -8193,7 +8215,8 @@  caller even if they are not marked @code
 function is integrated, then the function is not output as assembler code
 in its own right.
 
-Enabled at levels @option{-O1}, @option{-O2}, @option{-O3} and @option{-Os}.
+Enabled at levels @option{-O1}, @option{-O2}, @option{-O3} and @option{-Os},
+but not @option{-Og}.
 
 @item -fearly-inlining
 @opindex fearly-inlining
@@ -8321,7 +8344,8 @@  IA-64 and S/390.  Note that the @option{
 doesn't remove the decrement and branch instructions from the generated
 instruction stream introduced by other optimization passes.
 
-The default is @option{-fbranch-count-reg} at @option{-O1} and higher.
+The default is @option{-fbranch-count-reg} at @option{-O1} and higher,
+except for @option{-Og}.
 
 @item -fno-function-cse
 @opindex fno-function-cse
@@ -8489,14 +8513,16 @@  includes use of conditional moves, min,
 some tricks doable by standard arithmetics.  The use of conditional execution
 on chips where it is available is controlled by @option{-fif-conversion2}.
 
-Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}.
+Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}, but
+not with @option{-Og}.
 
 @item -fif-conversion2
 @opindex fif-conversion2
 Use conditional execution (where available) to transform conditional jumps into
 branch-less equivalents.
 
-Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}.
+Enabled at levels @option{-O}, @option{-O2}, @option{-O3}, @option{-Os}, but
+not with @option{-Og}.
 
 @item -fdeclone-ctor-dtor
 @opindex fdeclone-ctor-dtor
@@ -9071,7 +9097,8 @@  enabled by default at @option{-O} and hi
 Perform sparse conditional bit constant propagation on trees and propagate
 pointer alignment information.
 This pass only operates on local scalar variables and is enabled by default
-at @option{-O} and higher.  It requires that @option{-ftree-ccp} is enabled.
+at @option{-O1} and higher, except for @option{-Og}.
+It requires that @option{-ftree-ccp} is enabled.
 
 @item -ftree-ccp
 @opindex ftree-ccp
@@ -9089,7 +9116,8 @@  enabled by default at @option{-O} and hi
 @item -fssa-phiopt
 @opindex fssa-phiopt
 Perform pattern matching on SSA PHI nodes to optimize conditional
-code.  This pass is enabled by default at @option{-O} and higher.
+code.  This pass is enabled by default at @option{-O1} and higher,
+except for @option{-Og}.
 
 @item -ftree-switch-conversion
 @opindex ftree-switch-conversion
@@ -9311,13 +9339,14 @@  that have support for @option{-pthread}.
 @item -ftree-pta
 @opindex ftree-pta
 Perform function-local points-to analysis on trees.  This flag is
-enabled by default at @option{-O} and higher.
+enabled by default at @option{-O1} and higher, except for @option{-Og}.
 
 @item -ftree-sra
 @opindex ftree-sra
 Perform scalar replacement of aggregates.  This pass replaces structure
 references with scalars to prevent committing structures to memory too
-early.  This flag is enabled by default at @option{-O} and higher.
+early.  This flag is enabled by default at @option{-O1} and higher,
+except for @option{-Og}.
 
 @item -fstore-merging
 @opindex fstore-merging
@@ -10474,7 +10503,7 @@  Enabled with @option{-O3} and/or @option
 @item -fmove-loop-invariants
 @opindex fmove-loop-invariants
 Enables the loop invariant motion pass in the RTL loop optimizer.  Enabled
-at level @option{-O1}
+at level @option{-O1} and higher, except for @option{-Og}.
 
 @item -fsplit-loops
 @opindex fsplit-loops
Index: gcc/opts.c
===================================================================
--- gcc/opts.c	(revision 266082)
+++ gcc/opts.c	(working copy)
@@ -435,116 +435,127 @@  maybe_default_options (struct gcc_option
 			  lang_mask, handlers, loc, dc);
 }
 
-/* Table of options enabled by default at different levels.  */
+/* Table of options enabled by default at different levels.
+   Please keep this list sorted by level and alphabetized within
+   each level; this makes it easier to keep the documentation
+   in sync.  */
 
 static const struct default_options default_options_table[] =
   {
-    /* -O1 optimizations.  */
-    { OPT_LEVELS_1_PLUS, OPT_fdefer_pop, NULL, 1 },
-#if DELAY_SLOTS
-    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fdelayed_branch, NULL, 1 },
-#endif
-    { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 },
+    /* -O1 and -Og optimizations.  */
+    { OPT_LEVELS_1_PLUS, OPT_fcombine_stack_adjustments, NULL, 1 },
+    { OPT_LEVELS_1_PLUS, OPT_fcompare_elim, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_fcprop_registers, NULL, 1 },
+    { OPT_LEVELS_1_PLUS, OPT_fdefer_pop, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_fforward_propagate, NULL, 1 },
-    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion, NULL, 1 },
-    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion2, NULL, 1 },
+    { OPT_LEVELS_1_PLUS, OPT_fguess_branch_probability, NULL, 1 },
+    { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_fipa_pure_const, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_fipa_reference, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_fipa_reference_addressable, NULL, 1 },
-    { OPT_LEVELS_1_PLUS, OPT_fipa_profile, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_fmerge_constants, NULL, 1 },
+    { OPT_LEVELS_1_PLUS, OPT_fomit_frame_pointer, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_freorder_blocks, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_fshrink_wrap, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_fsplit_wide_types, NULL, 1 },
+    { OPT_LEVELS_1_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_ftree_ccp, NULL, 1 },
-    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_bit_ccp, NULL, 1 },
+    { OPT_LEVELS_1_PLUS, OPT_ftree_ch, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_ftree_coalesce_vars, NULL, 1 },
+    { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_ftree_dce, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_ftree_dominator_opts, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_ftree_dse, NULL, 1 },
-    { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 },
-    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_sra, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_ftree_fre, NULL, 1 },
-    { OPT_LEVELS_1_PLUS, OPT_ftree_copy_prop, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_ftree_sink, NULL, 1 },
-    { OPT_LEVELS_1_PLUS, OPT_ftree_ch, NULL, 1 },
-    { OPT_LEVELS_1_PLUS, OPT_fcombine_stack_adjustments, NULL, 1 },
-    { OPT_LEVELS_1_PLUS, OPT_fcompare_elim, NULL, 1 },
     { OPT_LEVELS_1_PLUS, OPT_ftree_slsr, NULL, 1 },
+    { OPT_LEVELS_1_PLUS, OPT_ftree_ter, NULL, 1 },
+
+    /* -O1 (and not -Og) optimizations.  */
     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fbranch_count_reg, NULL, 1 },
+#if DELAY_SLOTS
+    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fdelayed_branch, NULL, 1 },
+#endif
+    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion, NULL, 1 },
+    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fif_conversion2, NULL, 1 },
+    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_finline_functions_called_once, NULL, 1 },
     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fmove_loop_invariants, NULL, 1 },
-    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_pta, NULL, 1 },
     { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_fssa_phiopt, NULL, 1 },
-    { OPT_LEVELS_1_PLUS, OPT_ftree_builtin_call_dce, NULL, 1 },
-    { OPT_LEVELS_1_PLUS, OPT_fomit_frame_pointer, NULL, 1 },
+    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_bit_ccp, NULL, 1 },
+    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_sra, NULL, 1 },
+    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_ftree_pta, NULL, 1 },
 
-    /* -O2 optimizations.  */
-    { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fthread_jumps, NULL, 1 },
+    /* -O2 and -Os optimizations.  */
+    { OPT_LEVELS_2_PLUS, OPT_fcaller_saves, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fcode_hoisting, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_fcrossjumping, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_foptimize_sibling_calls, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_fcse_follow_jumps, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fgcse, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fdevirtualize, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fdevirtualize_speculatively, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_fexpensive_optimizations, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_frerun_cse_after_loop, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fcaller_saves, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fgcse, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fhoist_adjacent_loads, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fipa_bit_cp, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fipa_cp, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fipa_icf, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fipa_ra, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fipa_sra, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fipa_vrp, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fisolate_erroneous_paths_dereference, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_flra_remat, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_foptimize_sibling_calls, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_fpeephole2, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_frerun_cse_after_loop, NULL, 1 },
 #ifdef INSN_SCHEDULING
-  /* Only run the pre-regalloc scheduling pass if optimizing for speed.  */
-    { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fschedule_insns, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 },
 #endif
     { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 },
-    { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_freorder_blocks_algorithm_, NULL,
-      REORDER_BLOCKS_ALGORITHM_STC },
-    { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fcode_hoisting, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fstore_merging, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_fthread_jumps, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_ftree_pre, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_ftree_switch_conversion, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fipa_cp, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fipa_bit_cp, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fipa_vrp, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fdevirtualize, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fdevirtualize_speculatively, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fipa_sra, NULL, 1 },
-    { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_loops, NULL, 1 },
-    { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_jumps, NULL, 1 },
-    { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_labels, NULL, 1 },
-    { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_functions, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_ftree_tail_merge, NULL, 1 },
+    { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 },
     { OPT_LEVELS_2_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_CHEAP },
+
+    /* -O2 and -Os optimizations.  */
+    { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_functions, NULL, 1 },
+    { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_jumps, NULL, 1 },
+    { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_labels, NULL, 1 },
+    { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_falign_loops, NULL, 1 },
     { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_foptimize_strlen, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fhoist_adjacent_loads, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fipa_icf, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fisolate_erroneous_paths_dereference, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fipa_ra, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_flra_remat, NULL, 1 },
-    { OPT_LEVELS_2_PLUS, OPT_fstore_merging, NULL, 1 },
+    { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_freorder_blocks_algorithm_, NULL,
+      REORDER_BLOCKS_ALGORITHM_STC },
+#ifdef INSN_SCHEDULING
+  /* Only run the pre-regalloc scheduling pass if optimizing for speed.  */
+    { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_fschedule_insns, NULL, 1 },
+#endif
 
-    /* -O3 optimizations.  */
-    { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
-    { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribution, NULL, 1 },
-    { OPT_LEVELS_3_PLUS, OPT_floop_interchange, NULL, 1 },
-    { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
-    { OPT_LEVELS_3_PLUS, OPT_fsplit_paths, NULL, 1 },
+    /* -O3 and -Os optimizations.  */
     /* Inlining of functions reducing size is a good idea with -Os
        regardless of them being declared inline.  */
     { OPT_LEVELS_3_PLUS_AND_SIZE, OPT_finline_functions, NULL, 1 },
-    { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_finline_functions_called_once, NULL, 1 },
-    { OPT_LEVELS_3_PLUS, OPT_fsplit_loops, NULL, 1 },
-    { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 },
-    { OPT_LEVELS_3_PLUS, OPT_floop_unroll_and_jam, NULL, 1 },
+
+    /* -O3 optimizations.  */
     { OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 },
+    { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 },
+    { OPT_LEVELS_3_PLUS, OPT_floop_interchange, NULL, 1 },
+    { OPT_LEVELS_3_PLUS, OPT_floop_unroll_and_jam, NULL, 1 },
+    { OPT_LEVELS_3_PLUS, OPT_fpeel_loops, NULL, 1 },
+    { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
+    { OPT_LEVELS_3_PLUS, OPT_fsplit_loops, NULL, 1 },
+    { OPT_LEVELS_3_PLUS, OPT_fsplit_paths, NULL, 1 },
+    { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
+    { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribution, NULL, 1 },
     { OPT_LEVELS_3_PLUS, OPT_ftree_loop_vectorize, NULL, 1 },
+    { OPT_LEVELS_3_PLUS, OPT_ftree_partial_pre, NULL, 1 },
     { OPT_LEVELS_3_PLUS, OPT_ftree_slp_vectorize, NULL, 1 },
+    { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 },
     { OPT_LEVELS_3_PLUS, OPT_fvect_cost_model_, NULL, VECT_COST_MODEL_DYNAMIC },
-    { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 },
-    { OPT_LEVELS_3_PLUS, OPT_ftree_partial_pre, NULL, 1 },
-    { OPT_LEVELS_3_PLUS, OPT_fpeel_loops, NULL, 1 },
 
     /* -Ofast adds optimizations to -O3.  */
     { OPT_LEVELS_FAST, OPT_ffast_math, NULL, 1 },