From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25436 invoked by alias); 23 Jul 2007 19:22:58 -0000 Received: (qmail 25421 invoked by uid 48); 23 Jul 2007 19:22:48 -0000 Date: Mon, 23 Jul 2007 19:22:00 -0000 Subject: [Bug c/32871] New: Bad optimasation - Gcc is pushing to many registers X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "info at umfragen-service dot de" 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: 2007-07/txt/msg02362.txt.bz2 Let's look at this: long foo(long a, long b, long c, uint8_t d){ if(d){ return a+b; }else{ return a-c; } } The listing reports this: long foo(long a, long b, long c, uint8_t d){ 4e: cf 92 push r12 ;All this registers are pushed 50: ef 92 push r14 ;despite it's unessecary 52: ff 92 push r15 ; 54: 0f 93 push r16 56: 1f 93 push r17 if(d){ 58: cc 20 and r12, r12 5a: 29 f0 breq .+10 ; 0x66 return a+b; 5c: 62 0f add r22, r18 5e: 73 1f adc r23, r19 60: 84 1f adc r24, r20 62: 95 1f adc r25, r21 64: 04 c0 rjmp .+8 ; 0x6e }else{ return a-c; 66: 6e 19 sub r22, r14 68: 7f 09 sbc r23, r15 6a: 80 0b sbc r24, r16 6c: 91 0b sbc r25, r17 6e: 1f 91 pop r17 ;And they are getting restored 70: 0f 91 pop r16 ;despite they are not changed. 72: ff 90 pop r15 74: ef 90 pop r14 76: cf 90 pop r12 78: 08 95 ret During all operation in the low register (r3-r17) are always zero, and they are never changed in the hole file and even not in the function itself. So it's useless to push and pop them, we're only loosing time, space and ram. Please excuse my bad bug-reporting-style. This is my first report. For further explainaition I can recomment you the german site, where this problem is beeing discussed. http://www.roboternetz.de/phpBB2/viewtopic.php?p=300953 I hope you can fix this. Michael -- Summary: Bad optimasation - Gcc is pushing to many registers Product: gcc Version: 4.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: info at umfragen-service dot de GCC build triplet: Linux - Slax GCC host triplet: Linux - Slax GCC target triplet: avr http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32871