3 ms·
debugging ring0 code obfuscated by -O3 is another level of fun. ymmv, however the kernel guys are finding plenty of obscure bugs. and they have been bitten by
by froh 4y ago
debugging ring0 code obfuscated by -O3 is another level of fun. ymmv, however the kernel guys are finding plenty of obscure bugs.
and they have been bitten by aggressive smart optimizations based off undefined behavior.
for example testing a variable for != null after dereferencing it makes no sense. if it was null, it was a segfault and the check is never reached, right?
foo *x = f();
x->y();
if (x == null) {
/* unreachable in user space! */
do_sth_about_it();
...
}
so the check can go. except when it can't:
https://news.ycombinator.com/item?id=33770589 https://news.ycombinator.com/item?id=33770589
here is another recent discussion on -O2 vs -O3 here on HN.
https://news.ycombinator.com/item?id=28895896 https://news.ycombinator.com/item?id=28895896
seriously, by default, -O2 is for production code. use -O3 only after measuring it makes _your_ code faster and introduces no obscure bugs.
- mhh__ 4y agoI view the null check stuff as being more of an example of the compilers/even kernel Devs not bothering to try and properly express their desires i.e. in this case the check is has wording in the standard covering it, so it should be very explicitly desired to remain in the binary (volatility or similar, although there are limits to what you can ergonomically express in C) Similarly strict aliasing can change the behaviour of code but if you're genuinely relying on that your code is probably bad - either in the standards view, or in my view in that you can write the same code in a manner that won't cause any mischief (i.e. there are standard-friendly ways to do ugly pointer crap even if they mean memcpying pointers - which will then be eliminated by the optimizer)
- froh 4y ago> there are limits to what you can _ergonomically_ express in C... indeed. and in the context of this thread all I'm saying is that "-Oxxx is best, -Oyyy is outdated" is an oversimplification.