Bug 21580 - Less-than-ideal code generation for incrementing volatile variables
Summary: Less-than-ideal code generation for incrementing volatile variables
Status: RESOLVED DUPLICATE of bug 3506
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.0.1
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-15 09:23 UTC by Matthew Dempsky
Modified: 2007-08-18 00:21 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Dempsky 2005-05-15 09:23:12 UTC
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.)
Comment 1 Andrew Pinski 2005-05-15 13:03:36 UTC
There is another bug about this around somewhere.
Comment 2 Andrew Pinski 2005-05-15 13:34:26 UTC
This is invalid,  read the comments in PR 3506 which this is a dup of.

*** This bug has been marked as a duplicate of 3506 ***
Comment 3 Andrew Pinski 2007-08-18 00:21:33 UTC
>omewhat also related, "(void)x;" still accesses memory when x is volatile --
> I suppose this might be desirable, however.

It is because you say to load from x.