[LLVMbugs] [Bug 24057] New: Missed optimization for explicit little-endian loads

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jul 7 15:53:18 PDT 2015


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

            Bug ID: 24057
           Summary: Missed optimization for explicit little-endian loads
           Product: clang
           Version: 3.5
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: luto at mit.edu
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

--- begin code ---

struct eightbytes {
    unsigned char bytes[8];
} __attribute__((aligned(8)));

unsigned long long load_le64(const struct eightbytes *p)
{
    return ((unsigned long long)p->bytes[0] |
        (unsigned long long)p->bytes[1] << 8 |
        (unsigned long long)p->bytes[2] << 16 |
        (unsigned long long)p->bytes[3] << 24 |
        (unsigned long long)p->bytes[4] << 32 |
        (unsigned long long)p->bytes[5] << 40 |
        (unsigned long long)p->bytes[6] << 48 |
        (unsigned long long)p->bytes[7] << 56);
}

--- end code ---

GCC 5.1.1 (and 5.0 as well, I think) generates the obvious optimized code for
load_le64.  In fact, GCC 5.1.1 also gets the big-endian version right.  clang
generates a bunch of zero-extending loads, shifts, and ors.

Given that this more or less the canonical way of writing portable
serialization/deserialization code without relying on undefined or unspecified
behavior, it would be nice if clang generated good code for it.

Feel free to reassign from clang to LLVM if appropriate.

-- 
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/20150707/7d99a004/attachment.html>


More information about the llvm-bugs mailing list