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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to