From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5734 invoked by alias); 18 Sep 2011 13:23:48 -0000 Received: (qmail 5717 invoked by uid 22791); 18 Sep 2011 13:23:46 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,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; Sun, 18 Sep 2011 13:23:33 +0000 From: "gjl at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/50448] New: [avr] Missed optimization accessing struct component with known, absolute address. Date: Sun, 18 Sep 2011 13:38:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: missed-optimization 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: 2011-09/txt/msg01274.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50448 Bug #: 50448 Summary: [avr] Missed optimization accessing struct component with known, absolute address. Classification: Unclassified Product: gcc Version: 4.6.1 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: target AssignedTo: unassigned@gcc.gnu.org ReportedBy: gjl@gcc.gnu.org CC: eric.weddington@atmel.com Target: avr typedef struct { unsigned char a,b,c,d; } SPI_t; #define SPIE (*(SPI_t volatile*) 0x0AC0) void foo (void) { SPIE.d = 0xAA; while (!(SPIE.c & 0x80)); SPIE.d = 0xBB; while (!(SPIE.c & 0x80)); } avr-gcc-4.6.1 -Os -S -fdump-tree-optimized -fdump-rtl-expand compiles that code to foo: ldi r24,lo8(-86) ldi r30,lo8(2752) ldi r31,hi8(2752) std Z+3,r24 .L2: lds r24,2754 sbrs r24,7 rjmp .L2 ldi r24,lo8(-69) ldi r30,lo8(2752) ldi r31,hi8(2752) std Z+3,r24 .L3: lds r24,2754 sbrs r24,7 rjmp .L3 ret Instead of loading the address 2752 two times, it's sufficient to load it once or to do a direct access to 2755 and avoid loading the constant altogether. The load appeard first in .expand; .optimized looks fine: foo () { signed char D.1932; volatile unsigned char D.1931; signed char D.1930; volatile unsigned char D.1929; : MEM[(volatile struct SPI_t *)2752B].d ={v} 170; : D.1929_3 ={v} MEM[(volatile struct SPI_t *)2752B].c; D.1930_4 = (signed char) D.1929_3; if (D.1930_4 >= 0) goto ; else goto ; : MEM[(volatile struct SPI_t *)2752B].d ={v} 187; : D.1931_7 ={v} MEM[(volatile struct SPI_t *)2752B].c; D.1932_8 = (signed char) D.1931_7; if (D.1932_8 >= 0) goto ; else goto ; : return; }