http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52025
Bug #: 52025 Summary: caller-saves triggers a frame without need Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Keywords: missed-optimization, ra Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: g...@gcc.gnu.org CC: eric.wedding...@atmel.com Target: avr The following code triggers a frame even though there is just one local variable and there are plenty of call-saved registers. Apart from the optimization regression, this PR might be related to PR50925. Notice that the code is a minimized test case from the top-level code of a real-world embedded application. Therefore, the code runs in an infinite loop. extern void putch (char); extern char getch (void); extern void verify (void); void main_loop (void) { unsigned char c; for (;;) { getch(); c = getch(); verify(); putch (c); } } The generated code with -Os -dp -save-temps is main_loop: push r29 ; 36 *pushhi/1 [length = 2] push r28 push __tmp_reg__ ; 40 *addhi3_sp_R_pc2 [length = 1] in r28,__SP_L__ ; 41 *movhi_sp/2 [length = 2] in r29,__SP_H__ .L2: rcall getch ; 7 call_value_insn/3 [length = 1] rcall getch ; 9 call_value_insn/3 [length = 1] std Y+1,r24 ; 34 *movqi/3 [length = 1] rcall verify ; 12 call_insn/3 [length = 1] ldd r24,Y+1 ; 35 *movqi/4 [length = 1] rcall putch ; 15 call_insn/3 [length = 1] rjmp .L2 ; 44 jump [length = 1] The insns triggering the frame are 34 and 35. -fno-caller-saves resolves the issue and the code then then uses r17 to backup the value from getch. main_loop: push r17 ; 30 *pushqi/1 [length = 1] .L2: rcall getch ; 7 call_value_insn/3 [length = 1] rcall getch ; 9 call_value_insn/3 [length = 1] mov r17,r24 ; 10 *movqi/1 [length = 1] rcall verify ; 12 call_insn/3 [length = 1] mov r24,r17 ; 14 *movqi/1 [length = 1] rcall putch ; 15 call_insn/3 [length = 1] rjmp .L2 ; 33 jump [length = 1] Target: avr Configured with: ../../gcc.gnu.org/trunk/configure --target=avr --prefix=/home/georg/install/gcc-4.7 --enable-languages=c,c++ --disable-nls --disable-shared --disable-lto --disable-checking --disable-libquadmath --with-dwarf2 Thread model: single gcc version 4.7.0 20120102 (experimental) (GCC)