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

--- Comment #2 from andysem at mail dot ru ---
(In reply to Jakub Jelinek from comment #1)

In the godbolt link there is also a third case, which is similar to the second
one, but does not reuse the source register for comparison results.

unsigned int doubletmatch(unsigned int arr[], unsigned int key)
{
    unsigned count = 0;
    for (int i=0; i<1024 ; i++) {
        count += (arr[i] == key) | (arr[i] == ~key);
    }
    return count;
}

doubletmatch(unsigned int*, unsigned int):
        mov     r9d, esi
        not     r9d
        lea     rcx, [rdi+4096]
        xor     r8d, r8d
.L7:
        mov     edx, DWORD PTR [rdi]
        cmp     edx, esi
        sete    al
        cmp     edx, r9d
        sete    dl
        or      eax, edx
        movzx   eax, al
        add     rdi, 4
        add     r8d, eax
        cmp     rcx, rdi
        jne     .L7
        mov     eax, r8d
        ret

Note that in this case eax is not cleared either, so the "or eax, edx" has a
dependency on whatever prior instruction wrote to eax (before sete).

Reply via email to