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

            Bug ID: 97464
           Summary: Missed redundant store optimization opportunity
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pdimov at gmail dot com
  Target Milestone: ---

The code

    void f( int& x, float& y )
    {
        ++x;
        y = 1;
        --x;
    }

compiles to

    f(int&, float&):
        mov     eax, DWORD PTR [rdi]
        mov     DWORD PTR [rsi], 0x3f800000
        mov     DWORD PTR [rdi], eax
        ret

(https://godbolt.org/z/so4h3v)

but the load from, and the store to, [rdi] are redundant. It's obvious that
TBAA is active, but it for some reason doesn't go far enough.

This is a simplified example from "realer" code where x is a reference count
whose unnecessary manipulations could have been optimized out entirely.

Reply via email to