[llvm-bugs] [Bug 31162] New: LLVM (Clang) failed to optimized little-endian integer composition

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Nov 25 05:30:14 PST 2016


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

            Bug ID: 31162
           Summary: LLVM (Clang) failed to optimized little-endian integer
                    composition
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: peetlugen19 at yandex.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Clang/LLVM is unable to optimize this:

uint32_t read32le(const uint8_t* ptr) {
  return (static_cast<uint32_t>(ptr[0])    & 0x000000FFu) |
    ((static_cast<uint32_t>(ptr[1]) << 8)  & 0x0000FF00u) |
    ((static_cast<uint32_t>(ptr[2]) << 16) & 0x00FF0000u) |
    ((static_cast<uint32_t>(ptr[3]) << 24) & 0xFF000000u);
}

LLVM code:

read32le(unsigned char const*):
        movzx   eax, byte ptr [rdi]
        movzx   ecx, byte ptr [rdi + 1]
        shl     ecx, 8
        or      ecx, eax
        movzx   edx, byte ptr [rdi + 2]
        shl     edx, 16
        or      edx, ecx
        movzx   eax, byte ptr [rdi + 3]
        shl     eax, 24
        or      eax, edx
        ret

GCC (7) code:

read32le(unsigned char const*):
        mov     eax, DWORD PTR [rdi]
        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/20161125/94086a90/attachment-0001.html>


More information about the llvm-bugs mailing list