asm as "memory barrier"

Richard Henderson rth@redhat.com
Wed Apr 23 23:51:00 GMT 2003


On Wed, Apr 23, 2003 at 03:55:57PM -0400, Paul Koning wrote:
> But it also (as documented) causes the compiler to assume that memory
> has changed since then, i.e., anything it loaded before is no longer
> valid.  That's NOT what I want.

There doesn't appear to be any way to do this.  I'd have expected

  int x;
  int foo()
  {
    int r = x;
    {
      char *p;
      asm ("" : "=X"(p));
      asm volatile ("" : : "X"(*p));
    }
    return x + r;
  }

to work (as an observed read from a pointer with unknown value),
but it would seem that CSE doesn't want to combine the two loads
across the volatile asm.


r~



More information about the Gcc mailing list