Re:Depressing and faintly terrifying days for the C standard...
by glandium on Wednesday May 30, 2018 @06:52PM
(#17192589)
I was recently surprised to find that GCC, at -O0, does some level of optimization. At least it does for multiplications. https://godbolt.org/g/ekTkBm
Edit: the irony is that if you do compile with optimizations, it does a different optimization.
Re:Depressing and faintly terrifying days for the C standard...
by umanwizard on Wednesday May 30, 2018 @11:18PM
(#17193712)
What do you mean by "reasonable" ? Can you give an example of code that is compiled in a more obvious, straightforward way with O1 than O0 ?
Re:Depressing and faintly terrifying days for the C standard...
by loup-vaillant on Thursday May 31, 2018 @02:31AM
(#17194361)
My knowledge of this is only second hand, so I don't have any specific example. I believe Chandler Carruth explains this well on one of his LLVM talks (that is, how and why the front end emits crappy intermediate code, before the optmiser kicks in).
Hmm, nope. Sure, it will save you from much UB. But GCC and Clang have idiotic front ends. On purpose. They subscribe to the idea that the optimizer phase should clean up the front end mess. They're not entirely wrong, since it does simplify the front end, and does not really make the rest any more complex. It does make it slower, though.
Long story short, those compilers don't generate reasonable code by default. You need at least -O1.