Posted Aug 10, 2012 15:40 UTC (Fri) by daglwn (subscriber, #65432)
In reply to: ACCESS_ONCE() by quanstro
Parent article: ACCESS_ONCE()
> the claim above is that the choice is to
> (a) follow the standard, or
> (b) do something arbitrary.
This is a false choice. (a) and (b) are the same thing in the presence of undefined/unspecified/implementation-defined behavior. And it's not arbitrary. It's the decision of the compiler engineers.
> personally, i find this sort of code reorg by compilers
> to be problematic as it generally makes code quite hard
> to reason about. experienced developers would lift the
> assignment out of the loop if it mattered, and it were
I hear this a lot. Then people get surprised when I show them what the compiler did to their code. Believe me, there is no reason anyone should waste time hand-optimizing code without proof of need. Either they're going to miss a lot of opportunity or they are going to screw things up and make the compiler's job harder.
If a developer were to hand-optimize code to achieve the same performance result, the source code would be unmaintainable.
We want optimizing compilers. I can't believe anyone would suggest otherwise.