Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unrolling gcc compiler optimization

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

like image 486
user489023 Avatar asked Jan 21 '23 05:01

user489023


1 Answers

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")'
like image 184
Frédéric Hamidi Avatar answered Jan 29 '23 06:01

Frédéric Hamidi