public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/33111]  New: Bad code generation with -O2 (ARM 7 architecture)
@ 2007-08-19  7:49 gressau at optusnet dot com dot au
  2007-08-19  8:59 ` [Bug c/33111] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: gressau at optusnet dot com dot au @ 2007-08-19  7:49 UTC (permalink / raw)
  To: gcc-bugs

#define UIP_LLH_LEN 10000
#define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
#define u8_t unsigned char
#define u16_t unsigned short
#define UIP_BUFSIZE 1000

typedef struct {
  /* IP header. */
  u8_t vhl,
    tos,          
    len[2],       
    ipid[2],        
    ipoffset[2],  
    ttl,          
    proto;     
  u16_t ipchksum;
  u16_t srcipaddr[2], 
    destipaddr[2];

  /* TCP header. */
  u16_t srcport,
    destport;
  u8_t seqno[4],  
    ackno[4],
    tcpoffset,
    flags,
    wnd[2];     
  u16_t tcpchksum;
  u8_t urgp[2];
  u8_t optdata[4];
} uip_tcpip_hdr;


u8_t uip_buf[UIP_BUFSIZE+2];
volatile u8_t uip_acc32[4];

int jaroslav;

int main(void)
{
        if((BUF->ackno[0] == uip_acc32[0]) &&
                (BUF->ackno[1] == uip_acc32[1]) &&
                (BUF->ackno[2] == uip_acc32[2]) &&
                (BUF->ackno[3] == uip_acc32[3]))
                        jaroslav++;
        return 1;
}

        .file   "main.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        ldr     r0, .L10
        ldr     r1, .L10+4
        ldrb    r2, [r0, #28]   @ zero_extendqisi2
        ldrb    r3, [r1, #0]    @ zero_extendqisi2
        cmp     r2, r3
        @ lr needed for prologue
        beq     .L9
.L2:
        mov     r0, #1
        bx      lr
.L9:
        ldrb    r2, [r1, #1]    @ zero_extendqisi2
        ldrb    r3, [r0, #29]   @ zero_extendqisi2
        cmp     r3, r2
        bne     .L2
        ldrb    r2, [r1, #2]    @ zero_extendqisi2
        ldrb    r3, [r0, #30]   @ zero_extendqisi2
        cmp     r3, r2
        bne     .L2
        ldrb    r2, [r1, #3]    @ zero_extendqisi2
        ldrb    r3, [r0, #31]   @ zero_extendqisi2
        cmp     r3, r2 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!I THINK CC's OF THIS
COMPARE NEVER GET LOOKED AT
        ldreq   r2, .L10+8
        ldreq   r3, [r2, #0]
        addeq   r3, r3, #1
        streq   r3, [r2, #0]
        b       .L2
.L11:
        .align  2
.L10:
        .word   uip_buf+10000
        .word   uip_acc32
        .word   jaroslav
        .size   main, .-main
        .comm   uip_buf,1002,1
        .comm   uip_acc32,4,1
        .comm   jaroslav,4,4
        .ident  "GCC: (GNU) 4.2.0"


-- 
           Summary: Bad code generation with -O2 (ARM 7 architecture)
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gressau at optusnet dot com dot au


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


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

* [Bug c/33111] Bad code generation with -O2 (ARM 7 architecture)
  2007-08-19  7:49 [Bug c/33111] New: Bad code generation with -O2 (ARM 7 architecture) gressau at optusnet dot com dot au
@ 2007-08-19  8:59 ` pinskia at gcc dot gnu dot org
  2007-08-19 13:24 ` gressau at optusnet dot com dot au
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-08-19  8:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-08-19 08:59 -------
> #define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
Right there is an alias violation.


-- 


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


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

* [Bug c/33111] Bad code generation with -O2 (ARM 7 architecture)
  2007-08-19  7:49 [Bug c/33111] New: Bad code generation with -O2 (ARM 7 architecture) gressau at optusnet dot com dot au
  2007-08-19  8:59 ` [Bug c/33111] " pinskia at gcc dot gnu dot org
@ 2007-08-19 13:24 ` gressau at optusnet dot com dot au
  2007-08-19 22:23 ` gressau at optusnet dot com dot au
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gressau at optusnet dot com dot au @ 2007-08-19 13:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from gressau at optusnet dot com dot au  2007-08-19 13:23 -------
The attached sample code does not illustrate the real problem.
Further investigation is required why the code works with -O0 
and does not work with -O2.


-- 

gressau at optusnet dot com dot au changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|gressau at optusnet dot com |
                   |dot au                      |


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


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

* [Bug c/33111] Bad code generation with -O2 (ARM 7 architecture)
  2007-08-19  7:49 [Bug c/33111] New: Bad code generation with -O2 (ARM 7 architecture) gressau at optusnet dot com dot au
  2007-08-19  8:59 ` [Bug c/33111] " pinskia at gcc dot gnu dot org
  2007-08-19 13:24 ` gressau at optusnet dot com dot au
@ 2007-08-19 22:23 ` gressau at optusnet dot com dot au
  2007-08-19 22:24 ` gressau at optusnet dot com dot au
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gressau at optusnet dot com dot au @ 2007-08-19 22:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from gressau at optusnet dot com dot au  2007-08-19 22:22 -------
Created an attachment (id=14077)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14077&action=view)
This file does not compile correctly with -O2


-- 


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


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

* [Bug c/33111] Bad code generation with -O2 (ARM 7 architecture)
  2007-08-19  7:49 [Bug c/33111] New: Bad code generation with -O2 (ARM 7 architecture) gressau at optusnet dot com dot au
                   ` (2 preceding siblings ...)
  2007-08-19 22:23 ` gressau at optusnet dot com dot au
@ 2007-08-19 22:24 ` gressau at optusnet dot com dot au
  2007-08-19 22:25 ` gressau at optusnet dot com dot au
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gressau at optusnet dot com dot au @ 2007-08-19 22:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from gressau at optusnet dot com dot au  2007-08-19 22:24 -------
Created an attachment (id=14078)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14078&action=view)
This is the working unoptimized assembly of uip.c


-- 


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


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

* [Bug c/33111] Bad code generation with -O2 (ARM 7 architecture)
  2007-08-19  7:49 [Bug c/33111] New: Bad code generation with -O2 (ARM 7 architecture) gressau at optusnet dot com dot au
                   ` (3 preceding siblings ...)
  2007-08-19 22:24 ` gressau at optusnet dot com dot au
@ 2007-08-19 22:25 ` gressau at optusnet dot com dot au
  2007-09-09 20:44 ` gressau at optusnet dot com dot au
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gressau at optusnet dot com dot au @ 2007-08-19 22:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from gressau at optusnet dot com dot au  2007-08-19 22:25 -------
Created an attachment (id=14079)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14079&action=view)
This is the nonworking optimized assembly of uip.c


-- 


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


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

* [Bug c/33111] Bad code generation with -O2 (ARM 7 architecture)
  2007-08-19  7:49 [Bug c/33111] New: Bad code generation with -O2 (ARM 7 architecture) gressau at optusnet dot com dot au
                   ` (4 preceding siblings ...)
  2007-08-19 22:25 ` gressau at optusnet dot com dot au
@ 2007-09-09 20:44 ` gressau at optusnet dot com dot au
  2007-09-09 21:08 ` rask at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gressau at optusnet dot com dot au @ 2007-09-09 20:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from gressau at optusnet dot com dot au  2007-09-09 20:44 -------
Created an attachment (id=14180)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14180&action=view)
Test of optimized comparison (-O2)

Comparison of four consecutive bytes gets optimized (-O2) as comparison of a
word. The word address produced does not have the last two bits zero and the
ARM7 processor either ignores them (LPC2000) or data aborts (SAM7).


-- 

gressau at optusnet dot com dot au changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #14077|0                           |1
        is obsolete|                            |
  Attachment #14078|0                           |1
        is obsolete|                            |
  Attachment #14079|0                           |1
        is obsolete|                            |


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


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

* [Bug c/33111] Bad code generation with -O2 (ARM 7 architecture)
  2007-08-19  7:49 [Bug c/33111] New: Bad code generation with -O2 (ARM 7 architecture) gressau at optusnet dot com dot au
                   ` (5 preceding siblings ...)
  2007-09-09 20:44 ` gressau at optusnet dot com dot au
@ 2007-09-09 21:08 ` rask at gcc dot gnu dot org
  2007-09-09 22:23 ` gressau at optusnet dot com dot au
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rask at gcc dot gnu dot org @ 2007-09-09 21:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rask at gcc dot gnu dot org  2007-09-09 21:08 -------
Did you read comment #1?
Does -fno-strict-aliasing magically "fix" your code?


-- 


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


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

* [Bug c/33111] Bad code generation with -O2 (ARM 7 architecture)
  2007-08-19  7:49 [Bug c/33111] New: Bad code generation with -O2 (ARM 7 architecture) gressau at optusnet dot com dot au
                   ` (6 preceding siblings ...)
  2007-09-09 21:08 ` rask at gcc dot gnu dot org
@ 2007-09-09 22:23 ` gressau at optusnet dot com dot au
  2008-12-27  6:54 ` [Bug target/33111] " pinskia at gcc dot gnu dot org
  2009-05-22 14:51 ` rearnsha at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: gressau at optusnet dot com dot au @ 2007-09-09 22:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from gressau at optusnet dot com dot au  2007-09-09 22:23 -------
Subject: RE:  Bad code generation with -O2 (ARM 7 architecture)

The -fno-strict-aliasing does not fix the unaligned access.

-----Original Message-----
From: rask at gcc dot gnu dot org [mailto:gcc-bugzilla@gcc.gnu.org] 
Sent: Monday, 10 September 2007 07:08
To: gressau@optusnet.com.au
Subject: [Bug c/33111] Bad code generation with -O2 (ARM 7 architecture)



------- Comment #7 from rask at gcc dot gnu dot org  2007-09-09 21:08
-------
Did you read comment #1?
Does -fno-strict-aliasing magically "fix" your code?


-- 


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


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

* [Bug target/33111] Bad code generation with -O2 (ARM 7 architecture)
  2007-08-19  7:49 [Bug c/33111] New: Bad code generation with -O2 (ARM 7 architecture) gressau at optusnet dot com dot au
                   ` (7 preceding siblings ...)
  2007-09-09 22:23 ` gressau at optusnet dot com dot au
@ 2008-12-27  6:54 ` pinskia at gcc dot gnu dot org
  2009-05-22 14:51 ` rearnsha at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-12-27  6:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from pinskia at gcc dot gnu dot org  2008-12-27 06:53 -------
(In reply to comment #1)
> > #define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
> Right there is an alias violation.

More than that this is an alignment violation.  


-- 


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


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

* [Bug target/33111] Bad code generation with -O2 (ARM 7 architecture)
  2007-08-19  7:49 [Bug c/33111] New: Bad code generation with -O2 (ARM 7 architecture) gressau at optusnet dot com dot au
                   ` (8 preceding siblings ...)
  2008-12-27  6:54 ` [Bug target/33111] " pinskia at gcc dot gnu dot org
@ 2009-05-22 14:51 ` rearnsha at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2009-05-22 14:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from rearnsha at gcc dot gnu dot org  2009-05-22 14:51 -------
The ARM7 does not support unaligned accesses in the way that C programmers
normally expect (even if it doesn't fault them in the MMU then it still won't
fetch what you might expect -- see the CPU manuals for details).

As of ARM11 the rules were changed, but that's a different story...


-- 

rearnsha at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2009-05-22 14:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-19  7:49 [Bug c/33111] New: Bad code generation with -O2 (ARM 7 architecture) gressau at optusnet dot com dot au
2007-08-19  8:59 ` [Bug c/33111] " pinskia at gcc dot gnu dot org
2007-08-19 13:24 ` gressau at optusnet dot com dot au
2007-08-19 22:23 ` gressau at optusnet dot com dot au
2007-08-19 22:24 ` gressau at optusnet dot com dot au
2007-08-19 22:25 ` gressau at optusnet dot com dot au
2007-09-09 20:44 ` gressau at optusnet dot com dot au
2007-09-09 21:08 ` rask at gcc dot gnu dot org
2007-09-09 22:23 ` gressau at optusnet dot com dot au
2008-12-27  6:54 ` [Bug target/33111] " pinskia at gcc dot gnu dot org
2009-05-22 14:51 ` rearnsha at gcc dot gnu dot 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).