GCC optimization flag order

I would like to define a set of optimization sequences for the C input program to study the effect of my application sequences on code performance.

example:

gcc -fauto-inc-dec -fbranch-count-reg -fcombine-stack-adjustments ... test.c -o out.o 

Does the order of these parameters affect the efficiency of the generated code?

Also, does applying the optimization parameter have an effect twice?

Is there a better way to test thousands of optimization sequences? As in -02 (including about 20 options), I would like to define my own flags

+7
optimization c compiler-optimization gcc order
source share
1 answer
  • Does the order of these parameters affect the efficiency of the generated code?

    • No , the order of these parameters, passed as command line arguments to the compiler, does not affect the efficiency of the generated code.
  • Is there a better way to test thousands of optimization sequences?

    • Since we do not have the optimization sequence wrt optimization flags passed to the compiler, we have no way to check. But, as you know, we have optimization levels with which you can experiment.
  • Higher optimization levels perform more global transformations in the program and apply more expensive analysis algorithms to generate faster and more compact code. The price at compile time and, as a consequence, the improvement in runtime depend on the specific application and hardware environment. You have to experiment to find the best level for your application. See Optimization Levels for GCC

  • I would like to define my own flags

  • Gcc currently supports a lot of flags that you can find in Optimize settings . If you want to define a flag, then the compiler must understand this, and you may need to change the compiler code for gcc so that it can understand the new flag. Please refer to the code on github, opts.c , opts.c deals with flags and optimization levels.

  • In addition, does applying the optimization parameter twice matter?

    • No, applying one optimization option will not affect twice. For example: Executing gcc -fauto-inc-dec -fauto-inc-dec test.c will have the same effect as Executing gcc -fauto-inc-dec test.c

(Adding from comments regarding additional optimization checks - you can write a gcc optimization plugin to create additional passes. See this article: Introduction to creating GCC plugins . This article helps to create a plugin to perform additional optimization, code conversion or information analysis.)

+5
source share

All Articles