On Sat, 2 Jun 2018, Paul E. McKenney wrote: > One crude but effective workaround is to replicate the code following the > "if" statement into both legs of the "if" statement. This has the effect > of extending the control dependency to cover all of the code that used to > follow the "if" statement, leveraging herd's current limited knowledge of > compiler optimization. This workaround would of course be hopeless for > general Linux-kernel code, but should be at least semi-acceptable for the > very small snippets of code that can be accommodated within litmus tests. > > Please see the litmus test shown below, which uses this workaround, > allowing the smp_store_release() to be downgraded to WRITE_ONCE(). > > Given this workaround, crude though it might be, I believe that we can > take a more measured approach to identifying a longer-term solution. > > Thoughts? Yes, this works, although it is clearly just a stopgap. And obviously it can't be applied in situations where one of the legs of the "if" statement contains a non-trivial branch. In the long run, I don't think this problem is solvable. At least, not for all cases. It requires too much guesswork about what optimizations a compiler might do. Alan