public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/50448] New: [avr] Missed optimization accessing struct component with known, absolute address.
@ 2011-09-18 13:38 gjl at gcc dot gnu.org
  2011-09-18 13:41 ` [Bug target/50448] " gjl at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-09-18 13:38 UTC (permalink / raw)
  To: gcc-bugs

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;

<bb 2>:
  MEM[(volatile struct SPI_t *)2752B].d ={v} 170;

<bb 3>:
  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 <bb 3>;
  else
    goto <bb 4>;

<bb 4>:
  MEM[(volatile struct SPI_t *)2752B].d ={v} 187;

<bb 5>:
  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 <bb 5>;
  else
    goto <bb 6>;

<bb 6>:
  return;
}


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-11-05 20:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-18 13:38 [Bug target/50448] New: [avr] Missed optimization accessing struct component with known, absolute address gjl at gcc dot gnu.org
2011-09-18 13:41 ` [Bug target/50448] " gjl at gcc dot gnu.org
2011-09-29 16:00 ` [Bug middle-end/50448] [4.3/4.5/4.6/4.7 Regression] Missed optimization accessing struct component with integer address gjl at gcc dot gnu.org
2011-10-27 10:25 ` [Bug middle-end/50448] [4.5/4.6/4.7 " rguenth at gcc dot gnu.org
2011-10-28 13:00 ` gjl at gcc dot gnu.org
2011-10-28 14:27 ` bonzini at gnu dot org
2011-11-03 11:02 ` [Bug rtl-optimization/50448] " gjl at gcc dot gnu.org
2011-11-05 13:09 ` gjl at gcc dot gnu.org
2011-11-05 20:37 ` gjl at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).