https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97492
Bug ID: 97492 Summary: arm cortex-m0+ or constant value can use adds Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: kjetilos at gmail dot com Target Milestone: --- Given the following C code the compiler generates code that can be further optimized. void write_byte(void) { unsigned *regs = (unsigned *) 0x4210000; *regs = (*regs & ~0xff) | (0x9 & 0xff); } In this code the first byte is cleared and a constant 9 is or'ed into the word. This is compiled down to these instructions for cortex-m0+. write_byte: movs r3, #255 ldr r1, .L2 ldr r2, [r1] bics r2, r3 subs r3, r3, #246 orrs r3, r2 str r3, [r1] bx lr .L3: .align 2 .L2: .word 69271552 In this case where a constant less than 255 is or'ed into the last byte of a word then the subs + orrs instruction (or sometimes movs + orrs) sequence can be replaced by a single adds instruction to save 2 bytes.