public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/40844]  New: O2 optimizes out assignment to bitfield
@ 2009-07-24  5:22 jim at bodwin dot us
  2009-07-24  5:54 ` [Bug tree-optimization/40844] " pinskia at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jim at bodwin dot us @ 2009-07-24  5:22 UTC (permalink / raw)
  To: gcc-bugs

Incorrect code is produced for the following source with the O2 option.  In
particular, the assignment to the bitfield field2 is optimized out of the code
entirely and regImage is left all zero.  Correct code is produced with the O1
option and (at least) with gcc version 4.3.2.

====================  Source Code

typedef struct hwreg {
    short field1 : 4;
    short field2 : 2;
    short field3 : 10;
} hwreg_t;

void foo(volatile short *hwPtr, short f2) {
    hwreg_t regImage;           // Place to build reg image bit-by-bit
    *(short *) &regImage = 0;

    regImage.field2 = f2;

    *hwPtr = *((short *) &regImage);
}

============================ Object dump


/tmp/foo.o:     file format elf32-littlearm


Disassembly of section .text:

00000000 <foo>:
   0:   e3a03000        mov     r3, #0  ; 0x0
   4:   e24dd004        sub     sp, sp, #4      ; 0x4
   8:   e1c030b0        strh    r3, [r0]
   c:   e28dd004        add     sp, sp, #4      ; 0x4
  10:   e12fff1e        bx      lr

============================  gcc -v output

Configured with: ../gcc-4.4.1/configure --target=arm-elf --disable-__cxa_atexit
--with-newlib --enable-languages=c,c++ --with-gnu-as --with-gnu-ld
--with-gxx-include-dir=/home/jmb/arm-elf/include --prefix=/home/jmb/arm-elf :
(reconfigured) ../gcc-4.4.1/configure --target=arm-elf --disable-__cxa_atexit
--with-newlib --enable-languages=c,c++ --with-gnu-as --with-gnu-ld
--with-gxx-include-dir=/home/jmb/arm-elf/include --prefix=/home/jmb/arm-elf
Thread model: single
gcc version 4.4.1 (GCC)


-- 
           Summary: O2 optimizes out assignment to bitfield
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jim at bodwin dot us
 GCC build triplet: i486-pc-linux-gnu
  GCC host triplet: i486-pc-linux-gnu
GCC target triplet: arm-elf


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


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

* Re: [Bug tree-optimization/40844]  New: O2 optimizes out assignment to bitfield
  2009-07-24  5:22 [Bug tree-optimization/40844] New: O2 optimizes out assignment to bitfield jim at bodwin dot us
  2009-07-24  5:54 ` [Bug tree-optimization/40844] " pinskia at gmail dot com
@ 2009-07-24  5:54 ` Andrew Pinski
  2009-07-24 12:26 ` [Bug tree-optimization/40844] " rguenth at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Pinski @ 2009-07-24  5:54 UTC (permalink / raw)
  To: gcc-bugzilla; +Cc: gcc-bugs



Sent from my iPhone

On Jul 23, 2009, at 10:22 PM, "jim at bodwin dot us" <gcc-bugzilla@gcc.gnu.org 
 > wrote:

> Incorrect code is produced for the following source with the O2  
> option.  In
> particular, the assignment to the bitfield field2 is optimized out  
> of the code
> entirely and regImage is left all zero.  Correct code is produced  
> with the O1
> option and (at least) with gcc version 4.3.2.
>
> ====================  Source Code
>
> typedef struct hwreg {
>    short field1 : 4;
>    short field2 : 2;
>    short field3 : 10;
> } hwreg_t;
>
> void foo(volatile short *hwPtr, short f2) {
>    hwreg_t regImage;           // Place to build reg image bit-by-bit
>    *(short *) &regImage = 0;
>
>    regImage.field2 = f2;
>
>    *hwPtr = *((short *) &regImage);
> }

I think you are violating c/c++ aliasing rules here.


>
> ============================ Object dump
>
>
> /tmp/foo.o:     file format elf32-littlearm
>
>
> Disassembly of section .text:
>
> 00000000 <foo>:
>   0:   e3a03000        mov     r3, #0  ; 0x0
>   4:   e24dd004        sub     sp, sp, #4      ; 0x4
>   8:   e1c030b0        strh    r3, [r0]
>   c:   e28dd004        add     sp, sp, #4      ; 0x4
>  10:   e12fff1e        bx      lr
>
> ============================  gcc -v output
>
> Configured with: ../gcc-4.4.1/configure --target=arm-elf --disable- 
> __cxa_atexit
> --with-newlib --enable-languages=c,c++ --with-gnu-as --with-gnu-ld
> --with-gxx-include-dir=/home/jmb/arm-elf/include --prefix=/home/jmb/ 
> arm-elf :
> (reconfigured) ../gcc-4.4.1/configure --target=arm-elf --disable- 
> __cxa_atexit
> --with-newlib --enable-languages=c,c++ --with-gnu-as --with-gnu-ld
> --with-gxx-include-dir=/home/jmb/arm-elf/include --prefix=/home/jmb/ 
> arm-elf
> Thread model: single
> gcc version 4.4.1 (GCC)
>
>
> -- 
>           Summary: O2 optimizes out assignment to bitfield
>           Product: gcc
>           Version: 4.4.1
>            Status: UNCONFIRMED
>          Severity: critical
>          Priority: P3
>         Component: tree-optimization
>        AssignedTo: unassigned at gcc dot gnu dot org
>        ReportedBy: jim at bodwin dot us
> GCC build triplet: i486-pc-linux-gnu
>  GCC host triplet: i486-pc-linux-gnu
> GCC target triplet: arm-elf
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40844
>


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

* [Bug tree-optimization/40844] O2 optimizes out assignment to bitfield
  2009-07-24  5:22 [Bug tree-optimization/40844] New: O2 optimizes out assignment to bitfield jim at bodwin dot us
@ 2009-07-24  5:54 ` pinskia at gmail dot com
  2009-07-24  5:54 ` [Bug tree-optimization/40844] New: " Andrew Pinski
  2009-07-24 12:26 ` [Bug tree-optimization/40844] " rguenth at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gmail dot com @ 2009-07-24  5:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gmail dot com  2009-07-24 05:54 -------
Subject: Re:   New: O2 optimizes out assignment to bitfield



Sent from my iPhone

On Jul 23, 2009, at 10:22 PM, "jim at bodwin dot us" <gcc-bugzilla@gcc.gnu.org 
 > wrote:

> Incorrect code is produced for the following source with the O2  
> option.  In
> particular, the assignment to the bitfield field2 is optimized out  
> of the code
> entirely and regImage is left all zero.  Correct code is produced  
> with the O1
> option and (at least) with gcc version 4.3.2.
>
> ====================  Source Code
>
> typedef struct hwreg {
>    short field1 : 4;
>    short field2 : 2;
>    short field3 : 10;
> } hwreg_t;
>
> void foo(volatile short *hwPtr, short f2) {
>    hwreg_t regImage;           // Place to build reg image bit-by-bit
>    *(short *) &regImage = 0;
>
>    regImage.field2 = f2;
>
>    *hwPtr = *((short *) &regImage);
> }

I think you are violating c/c++ aliasing rules here.


>
> ============================ Object dump
>
>
> /tmp/foo.o:     file format elf32-littlearm
>
>
> Disassembly of section .text:
>
> 00000000 <foo>:
>   0:   e3a03000        mov     r3, #0  ; 0x0
>   4:   e24dd004        sub     sp, sp, #4      ; 0x4
>   8:   e1c030b0        strh    r3, [r0]
>   c:   e28dd004        add     sp, sp, #4      ; 0x4
>  10:   e12fff1e        bx      lr
>
> ============================  gcc -v output
>
> Configured with: ../gcc-4.4.1/configure --target=arm-elf --disable- 
> __cxa_atexit
> --with-newlib --enable-languages=c,c++ --with-gnu-as --with-gnu-ld
> --with-gxx-include-dir=/home/jmb/arm-elf/include --prefix=/home/jmb/ 
> arm-elf :
> (reconfigured) ../gcc-4.4.1/configure --target=arm-elf --disable- 
> __cxa_atexit
> --with-newlib --enable-languages=c,c++ --with-gnu-as --with-gnu-ld
> --with-gxx-include-dir=/home/jmb/arm-elf/include --prefix=/home/jmb/ 
> arm-elf
> Thread model: single
> gcc version 4.4.1 (GCC)
>
>
> -- 
>           Summary: O2 optimizes out assignment to bitfield
>           Product: gcc
>           Version: 4.4.1
>            Status: UNCONFIRMED
>          Severity: critical
>          Priority: P3
>         Component: tree-optimization
>        AssignedTo: unassigned at gcc dot gnu dot org
>        ReportedBy: jim at bodwin dot us
> GCC build triplet: i486-pc-linux-gnu
>  GCC host triplet: i486-pc-linux-gnu
> GCC target triplet: arm-elf
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40844
>


-- 


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


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

* [Bug tree-optimization/40844] O2 optimizes out assignment to bitfield
  2009-07-24  5:22 [Bug tree-optimization/40844] New: O2 optimizes out assignment to bitfield jim at bodwin dot us
  2009-07-24  5:54 ` [Bug tree-optimization/40844] " pinskia at gmail dot com
  2009-07-24  5:54 ` [Bug tree-optimization/40844] New: " Andrew Pinski
@ 2009-07-24 12:26 ` rguenth at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-07-24 12:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2009-07-24 12:26 -------
indeed.


-- 

rguenth at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2009-07-24 12:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-24  5:22 [Bug tree-optimization/40844] New: O2 optimizes out assignment to bitfield jim at bodwin dot us
2009-07-24  5:54 ` [Bug tree-optimization/40844] " pinskia at gmail dot com
2009-07-24  5:54 ` [Bug tree-optimization/40844] New: " Andrew Pinski
2009-07-24 12:26 ` [Bug tree-optimization/40844] " rguenth 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).