MSVC is the so-called Optimizing Compiler . OCs take the code you wrote and rewrite parts of it to minimize memory, increase execution speed, or both. They do this using deep technical knowledge of the platform on which the code should run, usually focusing on a specific set of instructions.
OCs such as MSVC, GCC, LLVM and many others use many different methods to achieve this. The techniques themselves go beyond what can be explained in the Internet message, even if I knew them all (which I donβt know). But there are some things you should keep in mind.
An optimized program is much more difficult to debug than one that was not. A lot of code could be moved in terms of both execution order and locality within the program, and characters are deleted.
In general, the Standard allows the compiler to make any change to your program that it wants, if the observed behavior of your program is the same " AS-IF ", there are no changes.
The parts of the compiler that are responsible for optimizing the code have been developed and written by special teams of very smart people over the years. The end result is a compiler that, by and large, optimizes your code much better than you might expect. As a rule, it makes no sense to try to implement your own micro-optimizations for two reasons. First, the compiler can usually do a better job, and the two micro-optimizations you write will mix the compiler with the ability to implement your own optimizations. By micro-optimizing your code manually, you can make your program worse.
source share