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

            Bug ID: 121355
           Summary: std::array comparison inside struct comparison does
                    not inline memcmp
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tdebock at DRWUK dot com
  Target Milestone: ---

On trunk with -O2, memcmps resulting from the std::array equality operator seem
to generally get inlined (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105751
solved by https://gcc.gnu.org/cgit/gcc/commit/?id=d13b86f932ff7b). However,
when using the defaulted equality operator on a struct that contains a
std::array, the memcmp call is still not inlined with -O2 (but is with -O3).

#include <array>
#include <cstdint>

struct A3 {
    int64_t x;
    std::array<int32_t, 2> a;

    bool operator==(const A3&) const = default;
};
bool f(const A3& x, const A3& y) {
    return x == y;
}
bool g(const std::array<int32_t, 2>& a, const std::array<int32_t, 2>& b) {
    return a == b;
}

with "-std=gnu++20 -O2" gives:

"f(A3 const&, A3 const&)":
        mov     rcx, QWORD PTR [rsi]
        cmp     QWORD PTR [rdi], rcx
        jne     .L6
        sub     rsp, 8
        add     rdi, 8
        add     rsi, 8
        mov     edx, 8
        call    "memcmp"
        test    eax, eax
        sete    al
        add     rsp, 8
        ret
.L6:
        xor     eax, eax
        ret
"g(std::array<int, 2ul> const&, std::array<int, 2ul> const&)":
        mov     rax, QWORD PTR [rsi]
        cmp     QWORD PTR [rdi], rax
        sete    al
        ret

Reply via email to