On Mon, Feb 4, 2013 at 4:31 PM, leon zadorin <leonleon77@xxxxxxxxx> wrote: > On Monday, 4 February 2013, Ian Lance Taylor wrote: >> >> On Sun, Feb 3, 2013 at 3:24 PM, John Fine <johnsfine@xxxxxxxxxxx> wrote: >> > >> > The optimizer changes that to the equivalent of >> > >> > *p = (expression of *p ) ? '-' : *p; >> > >> > Is that a valid optimization? >> >> Not these days, and current GCC should not do it. >> >> This is called a speculative store. >> > ... >> >> Speculative stores are >> disallowed by the C++11 memory model. > > > Just curious, given the: > 1) zero-overhead design principles of c++ standard (e.g. if one does not > want to use a given feature, then one does not pay overhead of using such a > feature). I'm afraid that is a goal rather than a principle. Even exceptions cost something even if you don't use them. > 2) one is not forced to use multithreaded programming in ones (c++) code. > 3) one can build GCC with single-threaded memory model (e.g. disable threads > during GCC config, etc.) > > Would GCC still use speculative store optimazations when a single-threaded > yet still -std=c++11 (i.e. with the use of rvalue refs and other c++11 > features) code is built by an instance of GCC which was configured without > support for "threaded-code"? I suppose it could in principle, but in practice the answer is no. Ian