http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54815
Bug #: 54815 Summary: [avr] missed optimization with operations with constant operands Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: other AssignedTo: unassig...@gcc.gnu.org ReportedBy: g...@gcc.gnu.org CC: eric.wedding...@atmel.com Target: avr Created attachment 28359 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28359 mov.c: C test case == C code == void f (int, int); void f_and (int x) { f (x, x & 0xff23); } void f_or (int x) { f (x, x | 42); } void f_xor (int x) { f (x, x ^ 0x80); } == Compile with == $ avr-gcc mov.c -S -Os -mmcu=atmega8 -dp The result is f_or: ldi r22,lo8(42) ; 15 *movhi/5 [length = 2] ldi r23,0 or r22,r24 ; 6 iorhi3/1 [length = 2] or r23,r25 rjmp f but the code could MOVW first to the destination and the IOR instead of loading the target with the const and then IOR against the source: f_or: movw r22,r24 ; *movhi [length = 1] ori r22,lo8(42) ; iorhi3 [length = 1] rjmp f Similar for the other test functions.