what are the compilation flags that are activated by using O3

Viewed 411

we are in the process of changing the intel compiler version from v14 to v18 in our systems and by running the tests, we have noticed that O3 in some cases produces incorrect results whereas the same code runs correctly with O3 and v14. I was wondering what are the differences in the optimizations between these two versions and how can I get a full list of flags that are getting activated by using O3 in each version. Thank you all in advance for your help and suggestions.

1 Answers

The behaviour of -O3 is documented on Intel's website: https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/optimization-options/o.html

O3

  • Performs O2 optimizations and enables more aggressive loop transformations such as Fusion, Block-Unroll-and-Jam, and collapsing IF statements.
  • This option may set other options. This is determined by the compiler, depending on which operating system and architecture you are using. The options that are set may change from release to release.
  • When O3 is used with options -ax or -x (Linux) or with options /Qax or /Qx (Windows), the compiler performs more aggressive data dependency analysis than for O2, which may result in longer compilation times.
  • The O3 optimizations may not cause higher performance unless loop and memory access transformations take place. The optimizations may slow down code in some cases compared to O2 optimizations.
  • The O3 option is recommended for applications that have loops that heavily use floating-point calculations and process large data sets.
  • Many routines in the shared libraries are more highly optimized for Intel® microprocessors than for non-Intel microprocessors.

The bottom of the page lists "Alternate options" which only lists -Od (which disables all optimizations: probably not what you want).

So it looks like -O3 activates optimizations that cannot be represented by using other flags (so -O3 does not have a long-form equivalent version).

Looking at Intel's page about the techniques used for high-level optimization, it looks like they cannot be enabled à la carte, so with HLO it's all-or-nothing and is enabled using either O2 or O3 (except that O2 uses a subset of O3's techniques).

Compare that to -Ofast which does have a long-form equivalent:

Ofast

  • It sets compiler options -O3, -no-prec-div, and -fp-model fast=2.
Related