This is the mail archive of the gcc-bugs@gcc.gnu.org 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]

[Bug c++/70091] New: Codegen emits dead load on x86-64


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70091

            Bug ID: 70091
           Summary: Codegen emits dead load on x86-64
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: deaeod at gmail dot com
  Target Milestone: ---

Code (http://goo.gl/MA8I0I):
struct bitfield {
    void and_assign() volatile {
        _raw = _and(_raw, 1); // this reads twice from _raw
        //mov     eax, DWORD PTR [rsp-24]
        //mov     eax, DWORD PTR [rsp-24]
        //and     eax, 1
        //mov     DWORD PTR [rsp-24], eax
        _raw = _raw & 1; // this reads once from _raw
        //mov     eax, DWORD PTR [rsp-24]
        //and     eax, 1
        //mov     DWORD PTR [rsp-24], eax
    }

    static unsigned _and(unsigned lhs, unsigned rhs) {
        return lhs & rhs;
    }

    unsigned _raw;
};

void test_device() {
    volatile bitfield tcc;

    tcc.and_assign();
}

I tested this snippet with g++ 4.8.2 and 4.9.0 on x86-64 only, so im not sure
if this bug applies to other targets. g++ 4.8.2 does not emit two loads from
_raw in any case, 4.9 and later behave as described in the comments. Note that
optimization level does not influence the generated code.

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