Using this version/config:
~~~~~~~~~~~~~~~~~`
Using built-in specs.
Target: avr
Configured with: ../gcc-4.1.2/configure --prefix=/c/WinAVR --target=avr
--enable
-languages=c,c++ --with-dwarf2 --enable-win32-registry=WinAVR-20070525
--disable
-nls --with-gmp=/usr/local --with-mpfr=/usr/local --enable-doc --disable-libssp
Thread model: single
gcc version 4.1.2 (WinAVR 20070525)
~~~~~~~~~~~~~~~~~~~~~~~~~~
Using this command line to compile:
avr-gcc -S -Os test.c -mmcu=atmega16
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The test case:
extern unsigned char foo(unsigned char in);
unsigned char test2(unsigned char input) {
input += foo(0xA); //use input
foo(0xA); //make sure input must be saved over the call
return input;
}
The assembler output:
/* prologue: frame size=0 */
push r16
push r17 <<Useless
/* prologue end (size=2) */
mov r17,r24
ldi r24,lo8(10)
call foo
mov r16,r24 <<Why?? add r17,r24 is much better
ldi r24,lo8(10)
call foo
add r17,r16 <<Could be gone if above statement used
mov r24,r17
clr r25
/* epilogue: frame size=0 */
pop r17
pop r16 <<Useless
ret
The adding is delayed until after the last call, but this requires saving an
extra register.
So delaying introduces:
an extra psh/pop
extra mov instruction
--
Summary: AVR unnessary register save
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: wvangulik at xs4all dot nl
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33050