打印优化级别的对应选项

例子

$ gcc -Q --help=optimizers
The following options control optimizations:
  -O<number>                          
  -Ofast                              
  -Os                                 
  -falign-functions                   [disabled]
  -falign-jumps                       [disabled]
  -falign-labels                      [disabled]
  -falign-loops                       [disabled]
  -fasynchronous-unwind-tables         [enabled]
  -fbranch-count-reg                  [enabled]
  -fbranch-probabilities              [disabled]
  -fbranch-target-load-optimize     [disabled]
  -fbranch-target-load-optimize2     [disabled]
  -fbtr-bb-exclusive                  [disabled]
  -fcaller-saves                      [disabled]
  -fcombine-stack-adjustments         [disabled]
  -fcommon                            [enabled]
  -fcompare-elim                      [disabled]
  -fconserve-stack                    [disabled]
  -fcprop-registers                   [disabled]
  -fcrossjumping                      [disabled]
  -fcse-follow-jumps                  [disabled]
  -fcx-fortran-rules                  [disabled]
  -fcx-limited-range                  [disabled]
  -fdata-sections                     [disabled]
  -fdce                               [enabled]
  -fdefer-pop                         [disabled]
  -fdelayed-branch                    [disabled]
  -fdelete-null-pointer-checks         [enabled]
  -fdevirtualize                      [disabled]
  -fdse                               [enabled]
  -fearly-inlining                    [enabled]
  -fexceptions                        [disabled]
  -fexpensive-optimizations           [disabled]
  -ffinite-math-only                  [disabled]
  -ffloat-store                       [disabled]
  -fforward-propagate                 [disabled]
  -fgcse                              [disabled]
  -fgcse-after-reload                 [disabled]
  -fgcse-las                          [disabled]
  -fgcse-lm                           [enabled]
  -fgcse-sm                           [disabled]
  -fgraphite-identity                 [disabled]
  -fguess-branch-probability          [disabled]
  -fhandle-exceptions                 
  -fif-conversion                     [disabled]
  -fif-conversion2                    [disabled]
  -finline-functions                  [disabled]
  -finline-functions-called-once     [enabled]
  -finline-small-functions            [disabled]
  -fipa-cp                            [disabled]
  -fipa-cp-clone                      [disabled]
  -fipa-matrix-reorg                  [disabled]
  -fipa-profile                       [disabled]
  -fipa-pta                           [disabled]
  -fipa-pure-const                    [disabled]
  -fipa-reference                     [disabled]
  -fipa-sra                           [disabled]
  -fivopts                            [enabled]
  -fjump-tables                       [enabled]
  -floop-block                        [disabled]
  -floop-flatten                      [disabled]
  -floop-interchange                  [disabled]
  -floop-parallelize-all              [disabled]
  -floop-strip-mine                   [disabled]
  -flto-report                        [disabled]
  -fltrans                            [disabled]
  -fmath-errno                        [enabled]
  -fmerge-all-constants               [disabled]
  -fmerge-constants                   [disabled]
  -fmodulo-sched                      [disabled]
  -fmove-loop-invariants              [enabled]
  -fnon-call-exceptions               [disabled]
  -fnothrow-opt                       [disabled]
  -fomit-frame-pointer                [disabled]
  -foptimize-register-move            [disabled]
  -foptimize-sibling-calls            [disabled]
  -fpack-struct                       [disabled]
  -fpack-struct=<number>              
  -fpeel-loops                        [disabled]
  -fpeephole                          [enabled]
  -fpeephole2                         [disabled]
  -fpredictive-commoning              [disabled]
  -fprefetch-loop-arrays              [enabled]
  -freg-struct-return                 [disabled]
  -fregmove                           [disabled]
  -frename-registers                  [enabled]
  -freorder-blocks                    [disabled]
  -freorder-blocks-and-partition     [disabled]
  -freorder-functions                 [disabled]
  -frerun-cse-after-loop              [disabled]
  -freschedule-modulo-scheduled-loops     [disabled]
  -frounding-math                     [disabled]
  -frtti                              [enabled]
  -fsched-critical-path-heuristic     [enabled]
  -fsched-dep-count-heuristic         [enabled]
  -fsched-group-heuristic             [enabled]
  -fsched-interblock                  [enabled]
  -fsched-last-insn-heuristic         [enabled]
  -fsched-pressure                    [disabled]
  -fsched-rank-heuristic              [enabled]
  -fsched-spec                        [enabled]
  -fsched-spec-insn-heuristic         [enabled]
  -fsched-spec-load                   [disabled]
  -fsched-spec-load-dangerous         [disabled]
  -fsched-stalled-insns               [disabled]
  -fsched-stalled-insns-dep           [enabled]
  -fsched2-use-superblocks            [disabled]
  -fschedule-insns                    [disabled]
  -fschedule-insns2                   [disabled]
  -fsection-anchors                   [disabled]
  -fsel-sched-pipelining              [disabled]
  -fsel-sched-pipelining-outer-loops     [disabled]
  -fsel-sched-reschedule-pipelined     [disabled]
  -fselective-scheduling              [disabled]
  -fselective-scheduling2             [disabled]
  -fshort-double                      [disabled]
  -fshort-enums                       [enabled]
  -fshort-wchar                       [disabled]
  -fsignaling-nans                    [disabled]
  -fsigned-zeros                      [enabled]
  -fsingle-precision-constant         [disabled]
  -fsplit-ivs-in-unroller             [enabled]
  -fsplit-wide-types                  [disabled]
  -fstrict-aliasing                   [disabled]
  -fstrict-enums                      [disabled]
  -fthread-jumps                      [disabled]
  -fno-threadsafe-statics             [enabled]
  -ftoplevel-reorder                  [enabled]
  -ftrapping-math                     [enabled]
  -ftrapv                             [disabled]
  -ftree-bit-ccp                      [disabled]
  -ftree-builtin-call-dce             [disabled]
  -ftree-ccp                          [disabled]
  -ftree-ch                           [disabled]
  -ftree-copy-prop                    [disabled]
  -ftree-copyrename                   [disabled]
  -ftree-cselim                       [enabled]
  -ftree-dce                          [disabled]
  -ftree-dominator-opts               [disabled]
  -ftree-dse                          [disabled]
  -ftree-forwprop                     [enabled]
  -ftree-fre                          [disabled]
  -ftree-loop-distribute-patterns     [disabled]
  -ftree-loop-distribution            [disabled]
  -ftree-loop-if-convert              [enabled]
  -ftree-loop-if-convert-stores     [disabled]
  -ftree-loop-im                      [enabled]
  -ftree-loop-ivcanon                 [enabled]
  -ftree-loop-optimize                [enabled]
  -ftree-lrs                          [disabled]
  -ftree-phiprop                      [enabled]
  -ftree-pre                          [disabled]
  -ftree-pta                          [enabled]
  -ftree-reassoc                      [enabled]
  -ftree-scev-cprop                   [enabled]
  -ftree-sink                         [disabled]
  -ftree-slp-vectorize                [enabled]
  -ftree-sra                          [disabled]
  -ftree-switch-conversion            [disabled]
  -ftree-ter                          [disabled]
  -ftree-vect-loop-version            [enabled]
  -ftree-vectorize                    [disabled]
  -ftree-vrp                          [disabled]
  -funit-at-a-time                    [enabled]
  -funroll-all-loops                  [disabled]
  -funroll-loops                      [disabled]
  -funsafe-loop-optimizations         [disabled]
  -funsafe-math-optimizations         [disabled]
  -funswitch-loops                    [disabled]
  -funwind-tables                     [disabled]
  -fvar-tracking                      [enabled]
  -fvar-tracking-assignments          [enabled]
  -fvar-tracking-assignments-toggle     [disabled]
  -fvar-tracking-uninit               [disabled]
  -fvariable-expansion-in-unroller     [disabled]
  -fvect-cost-model                   [enabled]
  -fvpt                               [disabled]
  -fweb                               [enabled]
  -fwhole-program                     [disabled]
  -fwpa                               [disabled]
  -fwrapv                             [disabled]

技巧

如上所示,使用-Q --help=optimizers选项可以打印出gcc的所有优化(相关的)选项,以及缺省情况下它们是否打开。类似的,你也可以查看不同优化级别下,这些优化选项是否打开:

$ gcc -Q --help=optimizers -O
$ gcc -Q --help=optimizers -O1
$ gcc -Q --help=optimizers -O2
$ gcc -Q --help=optimizers -O3
$ gcc -Q --help=optimizers -Og
$ gcc -Q --help=optimizers -Os
$ gcc -Q --help=optimizers -Ofast

详情参见gcc手册

贡献者

xmj