Albert Netymk
Albert Netymk

Reputation: 1112

How to find out which specific optimization affects my code significantly using gcc

I used to think that I can mimic -O1 in gcc by specifying -fauto-inc-dec and all the rest mentioned in optimization options for level one optimization. However, I was wrong because of one answer to this question.

Let's say -O1 indeed introduces significant impact on the code, then how can I find which optimization methods account for the difference?

EDIT:

I have used gcc -c -Q -O1 --help=optimizers, suggested in the answer to find out all the optimizer used in -O1, and use them using -foptimizer syntax. However, no significant difference is observed. Some optimizations don't have corresponding -foptimizer syntax, as mention in this question, and I guess the hidden ones are making huge difference in this case. How can I find them out?

Upvotes: 1

Views: 69

Answers (1)

ouah
ouah

Reputation: 145829

You can diff:

gcc -c -Q -O1 --help=optimizers

and

gcc -c -Q -O0 --help=optimizers

This gcc command will display the list of enabled and disabled optimizer options for both -O0 and -O1.

Then you can individually enable or disable specific optimizer options to see which one affects your program the most.

Upvotes: 3

Related Questions