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

Ivan Sorokin <vanyacpp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vanyacpp at gmail dot com

--- Comment #60 from Ivan Sorokin <vanyacpp at gmail dot com> ---
Another similar case. On this function:

unsigned wrap(unsigned index, unsigned limit)
{
    if (index >= limit)
        index -= limit;
    return index;
}

GCC 11.1 -O2 generates:

wrap(unsigned int, unsigned int):
        mov     edx, edi
        mov     eax, edi
        sub     edx, esi
        cmp     edi, esi
        cmovnb  eax, edx
        ret

I believe cmp here is redundant as the flags are already set after sub. After
removing cmp we get:

wrap(unsigned int, unsigned int):
        mov     edx, edi
        mov     eax, edi
        sub     edx, esi
        cmovnb  eax, edx
        ret

Now the register edx becomes unneeded:

wrap(unsigned int, unsigned int):
        mov     eax, edi
        sub     edi, esi
        cmovnb  eax, edi
        ret

Reply via email to