by nickelpro · 12mo ago · 0 comments
You generally avoid O3 because it's slower. Slower to compile, and slower to run. Aggressively unrolling loops and larger inlining windows bloat code size to the degree it impacts icache.
The optimization levels aren't "how fast do you want to code to go", they're "how aggressive do you want the optimizer to be." The most aggressive optimizations are largely unproven and left in O3 until they are generally useful, at which point they move to O2.
For example, people showed me
extern void g(int x);
int f(int a, int b)
{
g(b ? 42 : 43);
return a / b;
}
as an example on how compilers exploit "time-travelling" UB to optimize code, but it is just a compiler bug that got fixed once I reported it:https://developercommunity.visualstudio.com/t/Invalid-optimi...
Other compilers have similar issues.
That's a great bug you found, and of course it is a compiler bug, not UB.
99.9% of the bugs I've dealt with of this sort were just pointer aliasing. Or just use-after-free. Or just buffer overruns.
The median programmer, especially in the good ol' days, wrote UB code about once every 6-10 hours.