Why would GCC enable an optimization at O2/O3 when it explicitly says that it will slow the program?

Viewed 266

Quoted from https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html:

-falign-labels

-falign-labels=n

Align all branch targets to a power-of-two boundary, skipping up to n bytes like -falign-functions. This option can easily make code slower, because it must insert dummy operations for when the branch target is reached in the usual flow of the code.

-fno-align-labels and -falign-labels=1 are equivalent and mean that labels are not aligned.

If -falign-loops or -falign-jumps are applicable and are greater than this value, then their values are used instead.

If n is not specified or is zero, use a machine-dependent default which is very likely to be ‘1’, meaning no alignment.

Enabled at levels -O2, -O3.

Thinking about this flag more makes it lose even more sense... there are consequences of provoking code cache miss, and what even enabling means when parameter takes numeric value (1..)?

1 Answers
Related