How many GCC optimization levels are there?

后端 未结 4 1068
情深已故
情深已故 2020-11-28 20:07

How many GCC optimization levels are there?

I tried gcc -O1, gcc -O2, gcc -O3, and gcc -O4

If I use a really large number, it won\'t work.

However, I

4条回答
  •  难免孤独
    2020-11-28 20:12

    Seven distinct levels:

    • -O0 (default): No optimization.

    • -O or -O1 (same thing): Optimize, but do not spend too much time.

    • -O2: Optimize more aggressively

    • -O3: Optimize most aggressively

    • -Ofast: Equivalent to -O3 -ffast-math. -ffast-math triggers non-standards-compliant floating point optimizations. This allows the compiler to pretend that floating point numbers are infinitely precise, and that algebra on them follows the standard rules of real number algebra. It also tells the compiler to tell the hardware to flush denormals to zero and treat denormals as zero, at least on some processors, including x86 and x86-64. Denormals trigger a slow path on many FPUs, and so treating them as zero (which does not trigger the slow path) can be a big performance win.

    • -Os: Optimize for code size. This can actually improve speed in some cases, due to better I-cache behavior.

    • -Og: Optimize, but do not interfere with debugging. This enables non-embarrassing performance for debug builds and is intended to replace -O0 for debug builds.

    There are also other options that are not enabled by any of these, and must be enabled separately. It is also possible to use an optimization option, but disable specific flags enabled by this optimization.

    For more information, see GCC website.

提交回复
热议问题