[Patch] MIPS: Add missing memory clobbers to atomic memory insns.

Richard Sandiford richard@codesourcery.com
Sun Sep 9 18:19:00 GMT 2007


David Daney <ddaney@avtrex.com> writes:
> Richard Sandiford wrote:
>> Do all the sync loop patterns really need the clobber too?
>> The memory_barrier alone should be enough.
>
> I think any pattern that allows us to test the result of an atomic 
> operation requires a memory clobber.  Indeed gcc needs to track the 
> explicit dependencies of the operations.  However, I am worried about 
> the implicit dependencies that may only be known to the program author.  
> Presumably there are non-volatile reads that need to be protected by the 
> atomic memory operation.  The problem I was seeing with the 
> memory_barrier case I think would also occur with the other operations 
> as well.  For example in:
>
> -----------
> int a;
> int b;
> int q;
>
> void c()
> {
>   while (a)
>     {
>       if (__sync_add_and_fetch (&b, 1) == 5)
>     q++;
>     }
> }
> -----------
> What keeps loads of a and q from being hoisted outside of the loop?
>
> That is why I wanted to add memory clobbers to everything.  Although 
> correct code is being generated even without adding the clobbers.  Is 
> that due to chance, or is there some mechanism that prevents it?

Good question.  Apparently the answer is that the MEMs involved
have a special alias set (ALIAS_SET_MEMORY_BARRIER) that causes
them to be treated very much like (mem:BLK (scratch)).

Richard



More information about the Gcc-patches mailing list