That's interesting, could you send me the link where it states that? I Want to read more about it. Regardless, I still think this is a bit illogical behavior, considering how it's written, but good to know.
There's some discussion here:
There's lots more when you google "compiler memory reordering".
Another issue is that the processor does not execute instructions in order either, at least high performance processors don't. Memory is slow relative to the processor so the CPU would be waiting for memory most of the time if it was not clever about it.
That is typically hidden from the programmer until you start using multi-core processors and multithreading, or you are writing device drivers. Here's Herb Sutter's 2012 talk about it, in two parts:
Warning: this gets really hairy really fast, and is an endless source of entertaining bugs. When you port software from Intel/AMD to ARM the difference in memory models can expose all kinds of fun problems.