A question about "memory" clobbers in asm

Nathan Sidwell nathan@codesourcery.com
Mon Sep 20 15:39:00 GMT 2004


Dave Korn wrote:
>>-----Original Message-----

>   That should be considered a bug, shouldn't it?  I mean, the compiler knows
> that ptr is an input to the asm, so it should no more move "*ptr = 5" to
> after the asm than it should if there was a function call in the same
> place...
> 
>    *ptr = 5;
>    result = foo (ptr);
>    if (!result) {
>            ...
>    }
> 
>   IMO it would be obviously invalid to move the assignment past the function
> call in this case, and by analogy I don't think it should be valid in the
> asm case either.  Is there something I'm not getting here?
Yes, asms are not like function calls. The above asm is indistiguishable to
   *ptr = 5;
   result = ptr;
from a data-flow POV.

BTW, the asm
 > __asm__ volatile ("mov.l @%1,%0; mov #5,%2; cmp/eq %1,%2;
 > 			   movt %0"
 > 			   : "r" (result), "r" (temp)
 > 			   : "r" (ptr));
contains an error, in that it writes to the outputs before reading
the input.  The outputs should be marked as early clobbers.

> [  In fact, even if foo didn't take ptr as an argument, it still shouldn't
> be moving that assignment past the call to foo without having first done
> some fairly hefty alias analysis.... ]
yes, but not important in this case.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk




More information about the Gcc mailing list