From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15979 invoked by alias); 27 Jan 2012 23:06:43 -0000 Received: (qmail 15970 invoked by uid 22791); 27 Jan 2012 23:06:41 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_IB,TW_RJ X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 27 Jan 2012 23:06:29 +0000 From: "gjl at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/52025] New: caller-saves triggers a frame without need Date: Fri, 27 Jan 2012 23:22:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Keywords: missed-optimization, ra X-Bugzilla-Severity: normal X-Bugzilla-Who: gjl at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-01/txt/msg03222.txt.bz2 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: unassigned@gcc.gnu.org ReportedBy: gjl@gcc.gnu.org CC: eric.weddington@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)