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

            Bug ID: 128035
           Summary: failure to inline some memcmp when -mno-sse is passed
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mjguzik at gmail dot com
  Target Milestone: ---

Consider:

#define BUFSIZE 40

struct foo {
    char buf[BUFSIZE];
};

int test(struct foo *p1, struct foo *p2) {
    return __builtin_memcmp(p1, p2, sizeof(struct foo)) == 0;
}

Compiling with -O2 -mno-sse results in a call to memcmp. However, compiling
with mere -O2 gives inlined asm without simd. Thus I would expect such a result
for the -mno-sse case as well.

For reference:
-O2:
        sub     rsp, 8
        mov     edx, 40
        call    "memcmp"
        test    eax, eax
        sete    al
        add     rsp, 8
        movzx   eax, al
        ret

-O2 -mno-sse:
        mov     rax, QWORD PTR [rdi]
        mov     rdx, QWORD PTR [rdi+8]
        xor     rax, QWORD PTR [rsi]
        xor     rdx, QWORD PTR [rsi+8]
        or      rax, rdx
        je      .L5
.L2:
        mov     eax, 1
.L3:
        xor     eax, 1
        ret
.L5:
        mov     rax, QWORD PTR [rdi+16]
        mov     rdx, QWORD PTR [rdi+24]
        xor     rax, QWORD PTR [rsi+16]
        xor     rdx, QWORD PTR [rsi+24]
        or      rax, rdx
        jne     .L2
        mov     rax, QWORD PTR [rsi+32]
        cmp     QWORD PTR [rdi+32], rax
        jne     .L2
        xor     eax, eax
        jmp     .L3

Reply via email to