http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52558
torvald at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Component|tree-optimization |c++ --- Comment #12 from torvald at gcc dot gnu.org 2012-03-13 21:17:48 UTC --- (In reply to comment #11) > Just one remark: in this case the write introduction is incorrect wrt the > C++11 > memory model because there are no previous write to the same location. If > there had been a previous write to the same location, then the discriminating > context would have been racy and the code generated by -O2 sound. > > I believe that the above argument generalises to all write introductions but I > don't yet have a proof of this, so take it with a pinch of salt. We follow a similar line of reasoning when thinking about which transformations are allowed in transactional code (or other concurrent code). In principle, this also applies to loads to some extent even though racy loads are supposed to be okay for as--if as long as a value obtained from a racy read is never used. Having a more precise yet practical understanding of this would certainly help.