public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/43003]  New: Bitfield optimisation problem
@ 2010-02-08 22:29 zoltan at bendor dot com dot au
  2010-02-08 22:32 ` [Bug middle-end/43003] " pinskia at gcc dot gnu dot org
  2010-02-08 22:36 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: zoltan at bendor dot com dot au @ 2010-02-08 22:29 UTC (permalink / raw)
  To: gcc-bugs

The following C function:

typedef struct {

    unsigned    x : 1,
                y : 1,
                z : 1,
                a : 3,
                b : 18,
                c : 5;
} FOO;

extern volatile FOO var;

void    bar( void )
{
FOO x;

    x.x = 1;
    x.y = 0;
    x.z = 1;
    x.a = 0;
    x.b = 55;
    x.c = 0;

    var = x;
}

static  const FOO y = { 1,0,1,0,55,0 };

void    baz( void )
{
    var = y;
}

when compiled with -Os, -O2 or -O3 generates a very short function for bar():

        ldr     r3, .L3
        ldr     r2, .L3+4
        str     r2, [r3, #0]
        bx      lr
        .align  2
.L3:
        .word   var
        .word   3525

but a rather long one for baz:

        ldr     r3, .L7
        ldr     r2, [r3, #0]
        orr     r2, r2, #1
        str     r2, [r3, #0]
        ldr     r2, [r3, #0]
        bic     r2, r2, #2
        str     r2, [r3, #0]
        ldr     r2, [r3, #0]
        orr     r2, r2, #4
        str     r2, [r3, #0]
        ldr     r2, [r3, #0]
        bic     r2, r2, #56
        str     r2, [r3, #0]
        ldr     r2, [r3, #0]
        bic     r2, r2, #16711680
        bic     r2, r2, #61952
        orr     r2, r2, #3520
        str     r2, [r3, #0]
        ldr     r2, [r3, #0]
        bic     r2, r2, #520093696
        str     r2, [r3, #0]
        bx      lr
        .align  2
.L7:
        .word   var

It seems that when the compiler sees that 'y' is a constant, it generates a
sequence of individual field loads for structure members for a temporary
structure (just like what bar() does), but then it does not run the optimizer
over the generated sequence.


-- 
           Summary: Bitfield optimisation problem
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: zoltan at bendor dot com dot au
  GCC host triplet: i586-gnu-linux
GCC target triplet: arm-elf-none


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


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

* [Bug middle-end/43003] Bitfield optimisation problem
  2010-02-08 22:29 [Bug c/43003] New: Bitfield optimisation problem zoltan at bendor dot com dot au
@ 2010-02-08 22:32 ` pinskia at gcc dot gnu dot org
  2010-02-08 22:36 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-02-08 22:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-02-08 22:32 -------
I think this is an issue with volatile really.  Which was just fixed in the
last week or so.


-- 


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


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

* [Bug middle-end/43003] Bitfield optimisation problem
  2010-02-08 22:29 [Bug c/43003] New: Bitfield optimisation problem zoltan at bendor dot com dot au
  2010-02-08 22:32 ` [Bug middle-end/43003] " pinskia at gcc dot gnu dot org
@ 2010-02-08 22:36 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-02-08 22:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2010-02-08 22:36 -------
Yep in fact the fix for PR 42898 fixed this one also.

*** This bug has been marked as a duplicate of 42898 ***


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2010-02-08 22:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-08 22:29 [Bug c/43003] New: Bitfield optimisation problem zoltan at bendor dot com dot au
2010-02-08 22:32 ` [Bug middle-end/43003] " pinskia at gcc dot gnu dot org
2010-02-08 22:36 ` pinskia 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).