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

            Bug ID: 127562
           Summary: [Missed optimization]  SLP fails to coalesce adjacent
                    member movs
           Product: gcc
           Version: 16.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ofekshilon at gmail dot com
  Target Milestone: ---

Missed optimization I see in assignments and copy ctors:

```cpp
struct IntWrapper { int t; };
struct S { IntWrapper a; IntWrapper b; };

// SLP succeeds
void f1(S& s1, const S& s2 ) {
    s1 = s2;
}

// SLP fails
void f2(S& s1, const S& s2 ) {
    s1.a = s2.a;
    s1.b = s2.b;
}

// SLP succeeds again
void f3(S& s1, const S& s2 ) {
    s1.a.t = s2.a.t;
    s1.b.t = s2.b.t;
}
```
In the 'succeeds' case both mov's are unified to a single one:

        mov     rax, QWORD PTR [rsi]
        mov     QWORD PTR [rdi], rax

In the 'fails' cases they aren't:

        mov     eax, DWORD PTR [rsi]
        mov     DWORD PTR [rdi], eax
        mov     eax, DWORD PTR [rsi+4]
        mov     DWORD PTR [rdi+4], eax

Godbolt link: https://compiler-explorer.com/z/b8fazYn1s

Reply via email to