This is the mail archive of the
mailing list for the GCC project.
RE: [PR tree-optimization/52558]: RFC: questions on store data race
- From: "Boehm, Hans" <hans dot boehm at hp dot com>
- To: Richard Guenther <richard dot guenther at gmail dot com>, Aldy Hernandez <aldyh at redhat dot com>
- Cc: Richard Guenther <rguenther at suse dot de>, Andrew MacLeod <amacleod at redhat dot com>, gcc-patches <gcc-patches at gcc dot gnu dot org>, Torvald Riegel <triegel at redhat dot com>
- Date: Fri, 13 Apr 2012 23:30:31 +0000
- Subject: RE: [PR tree-optimization/52558]: RFC: questions on store data race
- References: <4F875324.firstname.lastname@example.org> <CAFiYyc2Cc2AgL75miwrENHZVywCVuxtUrE1RdO_A4VsiDJg3=A@mail.gmail.com>
> From: Richard Guenther [mailto:email@example.com]
> Can we _remove_ a store we percieve as redundant (with a single-threaded
> view) with the memory model?
Generally yes, so long as synchronization operations either conservatively treated as completely opaque, or are treated correctly in the "single-threaded view". If there is no synchronization between the original store, and the redundant one, then the redundant one changes things only if another thread writes to the same variable in-between. That constitutes a data race, which invokes undefined behavior. The general rule is that any sequentially correct transformation is OK between synchronization operations, so long as you don't store to anything you weren't supposed to modify, and the state at the next synchronization point is what would have been expected. You can sometimes treat synchronizations more aggressively, but that should be safe.