https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86520
Bug ID: 86520 Summary: AArch64: Two 8-bit accesses coalesced into a single 16-bit access Product: gcc Version: 7.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: swarren at nvidia dot com Target Milestone: --- When compiling for AArch64 (64-bit ARM), the following code: void func(char *str) { *str = '0'; str++; *str = 'x'; str++; } ... I believe should always perform two separate 8-bit accesses, simply because the compiler can't know whether str is aligned to anything more than byte alignment. With recent compilers without optimization, and with older compilers, the following code is generated: 0000000000000000 <func>: 0: 52800601 mov w1, #0x30 // #48 4: 39000001 strb w1, [x0] 8: 52800f01 mov w1, #0x78 // #120 c: 39000401 strb w1, [x0,#1] 10: d65f03c0 ret However, with any all Linaro gcc 7.x releases and -O3, those two byte writes are combined: 0000000000000000 <func>: 0: 528f0601 mov w1, #0x7830 // #30768 4: 79000001 strh w1, [x0] 8: d65f03c0 ret When this happens in the real code I'm compiling/execution, an alignment exception is thrown because str (x0) is only byte aligned not 16-bit aligned. I have not tested gcc-8.x yet, since I'm using Linaro binary releases not building from source.