Difference between -Os and -O2

Hieu Le Trung hieult@Cybersoft-VN.com
Tue Apr 28 09:59:00 GMT 2009


Eljay,

Let me try with the asm comparison, by the way, it's so huge and contains many source file :(

On my platform, the -Os does not have following flag: -freorder-blocks. It has all -O2 flags.

Here is the -Os flags
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
options passed:  -v -iprefix -march=mips32 -msoft-float -auxbase -Os
options enabled:  -feliminate-unused-debug-types -fdefer-pop
 -fomit-frame-pointer -foptimize-sibling-calls -funit-at-a-time
 -fcse-follow-jumps -fcse-skip-blocks -fexpensive-optimizations
 -fthread-jumps -fstrength-reduce -fpeephole -fforce-mem -ffunction-cse
 -fkeep-static-consts -fcaller-saves -fpcc-struct-return -fgcse -fgcse-lm
 -fgcse-sm -fgcse-las -floop-optimize -fcrossjumping -fif-conversion
 -fif-conversion2 -frerun-cse-after-loop -frerun-loop-opt
 -fdelete-null-pointer-checks -fschedule-insns -fschedule-insns2
 -fsched-interblock -fsched-spec -fsched-stalled-insns
 -fsched-stalled-insns-dep -fbranch-count-reg -fpic
 -freorder-functions
 -fcprop-registers -fcommon -fregmove -foptimize-register-move
 -fargument-alias -fstrict-aliasing -fmerge-constants
 -fzero-initialized-in-bss -fident -fpeephole2 -fguess-branch-probability
 -fmath-errno -ftrapping-math -mgas -msoft-float -mabicalls -meb
 -mexplicit-relocs -march=mips32 -mno-flush-func_flush_cache
 -mflush-func=_flush_cache


And here is the -O2 flags
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
options passed:  -v -iprefix -march=mips32 -msoft-float -auxbase -O2
options enabled:  -feliminate-unused-debug-types -fdefer-pop
 -fomit-frame-pointer -foptimize-sibling-calls -funit-at-a-time
 -fcse-follow-jumps -fcse-skip-blocks -fexpensive-optimizations
 -fthread-jumps -fstrength-reduce -fpeephole -fforce-mem -ffunction-cse
 -fkeep-static-consts -fcaller-saves -fpcc-struct-return -fgcse -fgcse-lm
 -fgcse-sm -fgcse-las -floop-optimize -fcrossjumping -fif-conversion
 -fif-conversion2 -frerun-cse-after-loop -frerun-loop-opt
 -fdelete-null-pointer-checks -fschedule-insns -fschedule-insns2
 -fsched-interblock -fsched-spec -fsched-stalled-insns
 -fsched-stalled-insns-dep -fbranch-count-reg -fpic
 -freorder-blocks
 -freorder-functions
 -fcprop-registers -fcommon -fregmove -foptimize-register-move
 -fargument-alias -fstrict-aliasing -fmerge-constants
 -fzero-initialized-in-bss -fident -fpeephole2 -fguess-branch-probability
 -fmath-errno -ftrapping-math -mgas -msoft-float -mabicalls -meb
 -mexplicit-relocs -march=mips32 -mno-flush-func_flush_cache
 -mflush-func=_flush_cache


Regards,
-Hieu

-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On Behalf Of John (Eljay) Love-Jensen
Sent: Monday, April 27, 2009 6:16 PM
To: Hieu Le Trung; GCC-help
Subject: Re: Difference between -Os and -O2

Hi Hieu Le Trung,

To expand upon Georg-Johann Lay¹s recommendation, I would do this:

echo '' | gcc -fverbose-asm -Os -S -x c - -o Os.s
echo '' | gcc -fverbose-asm -O2 -S -x c - -o O2.s
vi -d Os.s O2.s

On my platform, -Os has these additional flags over -O2:

-falign-jumps-max-skip
-falign-loops-max-skip
-finline-functions

While -O2 has this flag that -Os does not have:

-ftree-ch

Those may not be the same differences on your platform, though.

HTH,
--Eljay





More information about the Gcc-help mailing list