3 ms·
Naive question: Are there any compiler optimizations that -Ox makes possible which couldn't have been written originally as readable C code?
by jancsika 8y ago
Naive question:
Are there any compiler optimizations that -Ox makes possible which couldn't have been written originally as readable C code?
- BeeOnRope 8y agoFor sure. Consider idiom recognition, where a compiler takes a series of operations that implement some operation that isn't expressible as a language primitive and turns it into a single machine instruction that performs that operation. Rotate built up from a couple of shifts for example. Consider auto-vectorization for which the language has no direct support. Consider inlining and value-propagation and all the simplification can that occur when you combine them. Basically compile any non-trivial C program without optimization (or without some interesting optimization option) and with optimization, and look at the assembly. In many cases you wouldn't be able to write C code at all to reproduce the optimized version with the not-optimizing compiler. In other cases you could, but at the cost of code duplication or other things that would reduce the quality of your code.