views:

40

answers:

2

I am interested in seeing the code where gcc has actually optimized the code. Is there a way I could do?

I have gone through few other similar questoins, I have tried following few things,

  1. -Wa,ahl=filename.lst :- this option is really good, you can browse the code and corresponding machine code, but it is not good when I enable O3 option.
  2. Dumping optimized tree :- I am sure gcc is giving me good amount of debug information. But I do not how to decipher it. I will be glad if someone could point to any available information.

Is there any other better way, to find out what part of the code gcc optimized?

Thanks, Madhur

A: 

Look at the assember code or decompile your compiled application. C decompilers produce ugly C code, but for analyzing which code was generated, it have to suffice.

codymanix
+5  A: 

You can compile the code twice, first with:

$ gcc -O0 -S -o yourfile_o0.s

Then with:

$ gcc -O3 -S -o yourfile_o3.s

Then you can diff the two resulting assembly files:

$ diff -u yourfile_o0.s yourfile_o3.s
$ vim -d yourfile_o0.s yourfile_o3.s
$ emacs --eval '(ediff "yourfile_o0.s" "yourfile_o3.s")'
Frédéric Hamidi
+1, that's the way to do it most easily and most accurately.
DarkDust
+1, It's how I've done in the past during my more curious moments :-)
Chris J
Would you mind putting each command on a different line? I think it will better for reading. :)
Denilson Sá