https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65426
Bug ID: 65426 Summary: Recognize byte-swaps when writing to buffers Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: fuz at fuz dot su Created attachment 35036 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35036&action=edit Various instances of the aforementioned pattern It would be great if gcc could recognize code like this: static inline void wm32(uint8_t a[4], uint32_t x) { a[0] = x >> 24; a[1] = x >> 16; a[2] = x >> 8; a[3] = x >> 0; } and turn it into a single unaligned write (and perhaps a byte swap on platforms where this is supported). This kind of code appears when one tries to write marshalling code in a portable fashion. Attached is a file containing various instances of this pattern.