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

* [Bug target/50448] [avr] Missed optimization accessing struct component with known, absolute address.
  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 ` 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
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-09-18 13:41 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50448

Georg-Johann Lay <gjl at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011-09-18
   Target Milestone|---                         |4.7.0
     Ever Confirmed|0                           |1
      Known to fail|                            |4.3.3, 4.5.2, 4.6.1


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

* [Bug middle-end/50448] [4.3/4.5/4.6/4.7 Regression] Missed optimization accessing struct component with integer address
  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 ` 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
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-09-29 16:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50448

Georg-Johann Lay <gjl at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|target                      |middle-end
      Known to work|                            |3.4.6
            Summary|[avr] Missed optimization   |[4.3/4.5/4.6/4.7
                   |accessing struct component  |Regression] Missed
                   |with integer address        |optimization accessing
                   |                            |struct component with
                   |                            |integer address
      Known to fail|                            |4.7.0

--- Comment #1 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2011-09-29 15:55:05 UTC ---
As explained in http://gcc.gnu.org/ml/gcc/2011-09/msg00353.html this looks like
a middle-end flaw during tree -> RTL lowering in
explow.c:memory_address_addr_space() where the target cannot do anything about.

Changed component from TARGET to MIDDLE-END.


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

* [Bug middle-end/50448] [4.5/4.6/4.7 Regression] Missed optimization accessing struct component with integer address
  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 ` rguenth at gcc dot gnu.org
  2011-10-28 13:00 ` gjl at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-10-27 10:25 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50448

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
            Summary|[4.3/4.5/4.6/4.7            |[4.5/4.6/4.7 Regression]
                   |Regression] Missed          |Missed optimization
                   |optimization accessing      |accessing struct component
                   |struct component with       |with integer address
                   |integer address             |

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-10-27 10:24:56 UTC ---
Well, works "fine" on x86_64:

foo:
.LFB0:
        .cfi_startproc
        movb    $-86, 2755
.L2:
        movb    2754, %al
        testb   %al, %al
        jns     .L2
        movl    $2752, %eax
        movb    $-69, 3(%rax)
.L3:
        movb    2754, %al
        testb   %al, %al
        jns     .L3
        ret


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

* [Bug middle-end/50448] [4.5/4.6/4.7 Regression] Missed optimization accessing struct component with integer address
  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
                   ` (2 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-10-28 13:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50448

Georg-Johann Lay <gjl at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bonzini at gnu dot org

--- Comment #3 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2011-10-28 12:59:28 UTC ---
The issue is still present for avr (4.7 trunk r180399).

There is a patch proposed by Paolo that fixes the issue:

Can someone of you integrate that patch? I have no access to compile farm and
cannot test for all languages/targets/hosts that might be affected.



Index: cprop.c
===================================================================
--- cprop.c    (revision 177688)
+++ cprop.c    (working copy)
@@ -764,6 +764,18 @@ try_replace_reg (rtx from, rtx to, rtx i
     note = set_unique_reg_note (insn, REG_EQUAL, copy_rtx (src));
     }

+  if (set && MEM_P (SET_DEST (set)) && reg_mentioned_p (from, SET_DEST (set)))
+    {
+      /* If above failed and this is a single set, try to simplify the source
of
+     the set given our substitution.  We could perhaps try this for multiple
+     SETs, but it probably won't buy us anything.  */
+      rtx addr = simplify_replace_rtx (SET_DEST (set), from, to);
+
+      if (!rtx_equal_p (addr, SET_DEST (set))
+      && validate_change (insn, &SET_DEST (set), addr, 0))
+    success = 1;
+    }
+
   /* REG_EQUAL may get simplified into register.
      We don't allow that. Remove that note. This code ought
      not to happen, because previous code ought to synthesize


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

* [Bug middle-end/50448] [4.5/4.6/4.7 Regression] Missed optimization accessing struct component with integer address
  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
                   ` (3 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bonzini at gnu dot org @ 2011-10-28 14:27 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50448

--- Comment #4 from Paolo Bonzini <bonzini at gnu dot org> 2011-10-28 14:26:57 UTC ---
Can't you just test on x86_64-linux?


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

* [Bug rtl-optimization/50448] [4.5/4.6/4.7 Regression] Missed optimization accessing struct component with integer address
  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
                   ` (4 preceding siblings ...)
  2011-10-28 14:27 ` bonzini at gnu dot org
@ 2011-11-03 11:02 ` 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
  7 siblings, 0 replies; 9+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-11-03 11:02 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50448

--- Comment #5 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2011-11-03 11:01:55 UTC ---
(In reply to comment #0)

> 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
>     [...]

This is the code generated with Paolo's patch applied:

foo:
    ldi r24,lo8(-86)
    sts 2755,r24
.L2:
    lds r24,2754
    sbrs r24,7
    rjmp .L2
    ldi r24,lo8(-69)
    sts 2755,r24
    [...]


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

* [Bug rtl-optimization/50448] [4.5/4.6/4.7 Regression] Missed optimization accessing struct component with integer address
  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
                   ` (5 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-11-05 13:09 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50448

--- Comment #6 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2011-11-05 13:08:57 UTC ---
Author: gjl
Date: Sat Nov  5 13:08:54 2011
New Revision: 181011

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181011
Log:
    PR rtl-optimization/50448
    * cprop.c (try_replace_reg): Also try to replace uses of FROM that
    appear in SET_DEST.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cprop.c


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

* [Bug rtl-optimization/50448] [4.5/4.6/4.7 Regression] Missed optimization accessing struct component with integer address
  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
                   ` (6 preceding siblings ...)
  2011-11-05 13:09 ` gjl at gcc dot gnu.org
@ 2011-11-05 20:37 ` gjl at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-11-05 20:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50448

Georg-Johann Lay <gjl at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #7 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2011-11-05 20:37:25 UTC ---
Fixed in 4.7.0


^ 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).