From: "Ben Peddell" Newsgroups: comp.os.msdos.djgpp,gnu.gcc.help,gnu.utils.help References: Subject: Re: gcc -O3 & gprof Lines: 93 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Message-ID: Date: Tue, 18 Mar 2003 22:18:16 +1000 NNTP-Posting-Host: 144.139.175.207 X-Trace: newsfeeds.bigpond.com 1048041438 144.139.175.207 (Wed, 19 Mar 2003 13:37:18 EST) NNTP-Posting-Date: Wed, 19 Mar 2003 13:37:18 EST Organization: Telstra BigPond Internet Services (http://www.bigpond.com) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Alex Vinokur wrote in message news:b568o6$258tun$1 AT ID-79865 DOT news DOT dfncis DOT de... > > "Tauno Voipio" wrote in message news:Oejda.183$Zf2 DOT 42 AT read3 DOT inet DOT fi... > > > > "Alex Vinokur" wrote in message > [snip] > > > > > > ========= C code : BEGIN ========= > > > /* File main.c */ > > > > > > int foo1 (int argc) { return argc; } > > > int foo2 (int argc) { return argc; } > > > > The optimisation -O3 inlines simple functions (like yours here). There are > > no calls to trace. > [snip] > > How can we see that ? > For instance, nm doesn't distinguish -O0, -O1, -O2, -O3. > > ==================== > Windows 2000 > DJGPP 2.03 > GNU gcc/g++ version 3.2.1 > GNU nm 2.13 > ==================== > > gcc -o a0.exe main.c -g -pg > nm a0.exe | grep foo > 000016d0 T _foo1 > 000016e2 T _foo2 > > gcc -O1 -o a1.exe main.c -g -pg > nm a1.exe | grep foo > 000016d0 T _foo1 > 000016e2 T _foo2 > > gcc -O2 -o a2.exe main.c -g -pg > nm a2.exe | grep foo > 000016d0 T _foo1 > 000016f0 T _foo2 > > gcc -O3 -o a3.exe main.c -g -pg > nm a3.exe | grep foo > 000016f0 T _foo1 > 00001710 T _foo2 > > ================================= > Alex Vinokur > mailto:alexvn AT connect DOT to > http://www.simtel.net/pub/oth/19088.html > ================================= > > > Because you did not declare the functions static, they were still included as discrete functions in the output (so that other modules can access them). However, the compiler has also inlined copies of those functions in main() (since the functions were so simple). Your code: ========= C code : BEGIN ========= /* File main.c */ int foo1 (int argc) { return argc; } int foo2 (int argc) { return argc; } int main(int argc) { return (foo1(argc) + foo2(argc)); } ========= C code : END =========== is optimized by -O3 so that it appears to be: ========= C code : BEGIN ========= /* File main.c */ int foo1 (int argc) { return argc; } int foo2 (int argc) { return argc; } int main(int argc) { return ((argc) + (argc)); } ========= C code : END ===========