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++/84151] New: [4.9/5/6/7 Regression] g++ generates two identical loads in a volatile-qualified member function.


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

            Bug ID: 84151
           Summary: [4.9/5/6/7 Regression] g++ generates two identical
                    loads in a volatile-qualified member function.
           Product: gcc
           Version: 7.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wasing at mail dot ru
  Target Milestone: ---

The g++ generates two identical loads when the "foo" member function is called
in the following test case:

struct A {
    static int& bar(int& a) {
        return a;
    }

    int foo() volatile {
        int v = c;
        return bar(v);
    }

    int c;
};

A a;

int main() {
    a.c = 2;
    a.foo();

    return 0;
}


The -O2 options is used to get the following assembler:
        .file   "test_atomic.cpp"
        .section        .text.startup,"ax",@progbits
        .p2align 4,,15
        .globl  main
        .type   main, @function
main:
.LFB2:
        .cfi_startproc
        movl    $2, a(%rip)
        movl    a(%rip), %eax    
        movl    a(%rip), %eax  // !!!DUPLICATED
        xorl    %eax, %eax
        ret
        .cfi_endproc
.LFE2:
        .size   main, .-main
        .globl  a
        .bss
        .align 4
        .type   a, @object
        .size   a, 4
a:
        .zero   4
        .ident  "GCC: (GNU) 7.2.1 20170915 (Red Hat 7.2.1-2)"
        .section        .note.GNU-stack,"",@progbits

The "movl a(%rip), %eax" line is repeated twice. The
https://godbolt.org/g/yhQtDw reproduces the issue on many versions newer 4.8.

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