This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: A question about "memory" clobbers in asm

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

   *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 Sidwell    ::   ::     CodeSourcery LLC    ::

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]