https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78824
Bug ID: 78824 Summary: multiple add should in my opinion be optimized to multiplication Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: pj at hugeone dot co.uk Target Milestone: --- Hi Example (-O3) volatile uint16_t y; uint8_t nvx8; int main(void) { y = nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8; } translated to: y = nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8 + nvx8; 94: 80 91 00 01 lds r24, 0x0100 98: 28 2f mov r18, r24 9a: 30 e0 ldi r19, 0x00 ; 0 9c: c9 01 movw r24, r18 9e: 88 0f add r24, r24 a0: 99 1f adc r25, r25 a2: 88 0f add r24, r24 a4: 99 1f adc r25, r25 a6: 82 0f add r24, r18 a8: 93 1f adc r25, r19 aa: 82 0f add r24, r18 ac: 93 1f adc r25, r19 ae: 82 0f add r24, r18 b0: 93 1f adc r25, r19 b2: 82 0f add r24, r18 b4: 93 1f adc r25, r19 b6: 82 0f add r24, r18 b8: 93 1f adc r25, r19 ba: 82 0f add r24, r18 bc: 93 1f adc r25, r19 be: 82 0f add r24, r18 c0: 93 1f adc r25, r19 c2: 82 0f add r24, r18 c4: 93 1f adc r25, r19 c6: 82 0f add r24, r18 c8: 93 1f adc r25, r19 ca: 82 0f add r24, r18 cc: 93 1f adc r25, r19 ce: 82 0f add r24, r18 d0: 93 1f adc r25, r19 d2: 82 0f add r24, r18 d4: 93 1f adc r25, r19 d6: 90 93 02 01 sts 0x0102, r25 da: 80 93 01 01 sts 0x0101, r24 It should be optimized to multiplication I think.