News for hackers. Stuff that matters.
Re:GodBolt: Enter C, get Assembly by digler999 on Thursday December 15, 2016 @10:51AM (#13185362)
> I do expect compilers to be at least this smart.

Does anyone know if, internally, compilers second-guess / double-check themselves ? For instance, when they detect a clever shortcut do they generate and quickly run [1] the optimized bytecode on a sampling of inputs to verify it is functionally-equivalent to what non-optimized bytecode outputs ?

[1] obviously cross-compilers are a thing, so this wouldn't be possible if it were compiling/optimizing for a separate architecture.

Re:GodBolt: Enter C, get Assembly by CyberShadow on Thursday December 15, 2016 @11:17AM (#13185634)
> For instance, when they detect a clever shortcut do they generate and quickly run [1] the optimized bytecode on a sampling of inputs to verify it is functionally-equivalent to what non-optimized bytecode outputs ?

No. Optimization transformations are generally expected to result in provably identically-functional code (or sufficiently identical, in case of e.g. floating-point optimizations). Otherwise it is a bug.

Re:GodBolt: Enter C, get Assembly by vsl on Friday December 16, 2016 @06:50AM (#13192619)
Indeed, “provably” being the key word. If I, the compiler developer, prove (in the mathematical sense) that the transformation is functionally identical, I don’t need the compiler to run any experiments to verify it. A proof is much more solid than running a few experiments.
Re:GodBolt: Enter C, get Assembly by jcranmer on Thursday December 15, 2016 @11:17AM (#13185624)
Detecting functional equivalence of Turing-complete languages is a very non-trivial problem. So, no, compilers don't try to construct runtime proofs of their correctness.

There are people who do do more exhaustive checks of the peephole optimizations for correctness--or finding new opportunities (see John Regehr's Souper work). But production compilers are well-known (at least by anyone who works on them) for having lots of bugs in these kinds of optimizations.

Re:GodBolt: Enter C, get Assembly by drdrey on Thursday December 15, 2016 @03:25PM (#13187987)
I think Nuno Lopes also did some work on proving the correctness of instcombine optimizations, for instance: http://blog.regehr.org/archives/1170