[llvm-bugs] [Bug 42324] New: Extra mov in naive int swap

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 19 06:20:45 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=42324

            Bug ID: 42324
           Summary: Extra mov in naive int swap
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at rotateright.com

#include <algorithm>
unsigned int stdswap(unsigned int u, unsigned int v)
{
    if(u>v) std::swap(u,v);

    return u / v;
}

unsigned int naiveswap(unsigned int u, unsigned int v)
{
    if (u > v) {
            unsigned int t = v;
            v = u;
            u = t;
    }

    return u / v;
}

Clang -O3:
stdswap(unsigned int, unsigned int):
        cmp     edi, esi
        mov     eax, edi
        cmova   eax, esi
        cmova   esi, edi
        xor     edx, edx
        div     esi
        ret

naiveswap(unsigned int, unsigned int):
        mov     eax, edi
        cmp     edi, esi
        mov     ecx, esi // this mov
        cmova   ecx, edi
        cmova   eax, esi
        xor     edx, edx
        div     ecx
        ret

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190619/1e11fce9/attachment.html>


More information about the llvm-bugs mailing list