On Sat, 1 Mar 2025, Martin Uecker via Gcc wrote:
> > > What was the reason to disallow those optimizations that > > > could be allowed by default? > > > > -fallow-store-data-races guards transforms that we know to be incorrect > > for source code that may become a part of a multithreaded program. > > Are you asking about something else? > > I am looking for an example where stores are invented but this > is allowed by C11. So something such as > > if (x != 1) > x = 1; > > being transformed to > > x = 1; > > this should not harm another reader for x == 1 and if > there is a writer it is UB anyway, so this should be ok. Does GCC > do such things? I'm not aware of any. In addition for the transform to be correct in the abstract, the compiler would need to be sure that 'x' does not reside in read-only memory. And then, as Richi said, this may be a de-optimization if you consider the costs of dirtying a cache line conditionally or always (or, for a more dramatic case, triggering a page fault or not). Alexander