With gcc 4.0.1, the following code on i386 (using -O3 -fomit-frame-pointer):

    int x;

    void
    foo (void)
    {
      ++x;
    }

compiles to:

    foo:
        incl x
        ret

However, when x is changed to a volatile this instead compiles to:

    foo:
        movl    x, %eax
        incl    %eax
        movl    %eax, x
        ret

Similar degredations in the quality of generated code exists for statements like
--x, x += 2, etc when x is marked volatile.  (Somewhat also related, "(void)x;"
still accesses memory when x is volatile -- I suppose this might be desirable,
however.)

-- 
           Summary: Less-than-ideal code generation for incrementing
                    volatile variables
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mrd at alkemio dot org
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21580

Reply via email to