From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29234 invoked by alias); 10 Mar 2014 15:17:20 -0000 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 Received: (qmail 29208 invoked by uid 48); 10 Mar 2014 15:17:11 -0000 From: "darryl.piper at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug other/60486] New: [avr] missed optimization on detecting zero flag set Date: Mon, 10 Mar 2014 15:17:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: other X-Bugzilla-Version: 4.8.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: darryl.piper at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-03/txt/msg00789.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60486 Bug ID: 60486 Summary: [avr] missed optimization on detecting zero flag set Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: darryl.piper at gmail dot com detection of a variable being decremented to reach zero missed optimization. int main(uint16_t, uint16_t ); int main(uint16_t x, uint16_t y) { uint16_t z = x; while (x > y) { if ( --z == 0 ) return 1; x++; } return 0; } produces with gcc 4.8.0 and 4.8.1 and I expect 4.8.2 as well. compiled with -Os the code at 0x82 to 0x8a uses a compare against zero, when the subi and sbc, leave the zero flag set on a atmega8. 7a: 9c 01 movw r18, r24 7c: 68 17 cp r22, r24 7e: 79 07 cpc r23, r25 80: 38 f4 brcc .+14 ; 0x90 82: 21 50 subi r18, 0x01 ; 1 84: 31 09 sbc r19, r1 86: 21 15 cp r18, r1 88: 31 05 cpc r19, r1 8a: 29 f0 breq .+10 ; 0x96 8c: 01 96 adiw r24, 0x01 ; 1 8e: f6 cf rjmp .-20 ; 0x7c 90: 80 e0 ldi r24, 0x00 ; 0 92: 90 e0 ldi r25, 0x00 ; 0 94: 08 95 ret 96: 81 e0 ldi r24, 0x01 ; 1 98: 90 e0 ldi r25, 0x00 ; 0 9a: 08 95 ret in gcc/config/avr/avr.md the code for (define_insn "add3" no longer says it alters the zero of negative flag which the 4.7.2 branch did depending on which choice of add & adc or sub & sbc choice it used.