2

I found a lot of Optimization Options here

While going through them I found some of them have side-effects (like makes debugging impossible). In my experience I have found the -O1 to -O3 and -Os most commonly used. But, what are the other options which are commonly used in your projects?

Jay
  • 24,173
  • 25
  • 93
  • 141

2 Answers2

3

-ffast-math can have a significant performance impact on floating point intensive software.

Also, compiling specific for the target processor using the appropriate -march= option may have a slight performance impact, but strictly speaking, this is not an optimizing option.

UncleZeiv
  • 18,272
  • 7
  • 49
  • 77
Gunther Piez
  • 29,760
  • 6
  • 71
  • 103
  • You should note that this option horribly breaks IEEE 754 conformance and should only be used if you're sure that's okay. In practice that means it's okay to use if you're treating floating point numbers as random bad approximations of real numbers, but not if you're using them in any precise way. – R.. GitHub STOP HELPING ICE Nov 24 '10 at 16:21
  • No, not his again ;-) In my opinion, software that relies on the differences of IEEE754 implementation of -ffast-math and without can be considered broken. Because it relies on the exact comparison of floats. -fno-fast-math will make your program in no way more "precise" or the floats not more "exact". What it will do is change the behaviour of NaNs, and if your software has a lot of these, you have bigger problems. There is one exception: software which contains some IEEE754 funtions like isNaN() (which are actually never used, ever), most commonly found in interpreters like python or mysql. – Gunther Piez Nov 25 '10 at 08:38
1

-march=native with recent versions of gcc removes all the headache of determining the platform on which you are compiling.

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177
  • 1
    Unfortunatly, not _all_ the headache. On my machine, a 45 nm Core 2, -march=native or even -march=core2 activates all the neccessary things including and up to -msse3 and -mssse3, but not the -msse4_1 instruction set, which is available at this processor (but not on the 65 nm model!). Some of the SSE4.1 instructions are actually generated and used from "normal" C code if -ftree-vectorize is activated (at -O3). The performance difference is of course hardly measureable – Gunther Piez Nov 24 '10 at 14:17
  • @drhirsch: +1 for the final sentence of your comment. :-) – R.. GitHub STOP HELPING ICE Nov 24 '10 at 16:19