public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/42898]  New: Problem initializing volatile structures
@ 2010-01-29 19:27 gandalf at winds dot org
  2010-01-29 19:38 ` [Bug c/42898] [4.3/4.4/4.5 Regression] volatile structures and compound literals pinskia at gcc dot gnu dot org
                   ` (23 more replies)
  0 siblings, 24 replies; 25+ messages in thread
From: gandalf at winds dot org @ 2010-01-29 19:27 UTC (permalink / raw)
  To: gcc-bugs

I've recently upgraded to GCC 4.3.2 from 4.2.2, and I noticed a strange
change in how volatile bitmask structures are optimized.

Consider the following code (compiled using just the -O3 option):


/* 32-bit MMIO */
struct hardware {
  int parm1:8;
  int :4;
  int parm2:4;
  int parm3:15;
  int parm4:1;
};

void f1()
{
  volatile struct hardware *ptr=(void *)0x11223344;

  *ptr=(struct hardware) {
    .parm1=42,
    .parm2=13,
    .parm3=11850,
    .parm4=1,
  };
}

void f2()
{
  volatile struct hardware *ptr=(void *)0x11223344;

  struct hardware set={
    .parm1=42,
    .parm2=13,
    .parm3=11850,
    .parm4=1,
  };

  *ptr=set;
}


In GCC 4.3.2, this produces the following assembly:

f1:
        movl    $0, 287454020
        movb    $42, 287454020
        movl    287454020, %eax
        andb    $15, %ah
        orb     $208, %ah
        movl    %eax, 287454020
        movl    287454020, %eax
        andl    $-2147418113, %eax
        orl     $776601600, %eax
        movl    %eax, 287454020
        movl    287454020, %eax
        orl     $-2147483648, %eax
        movl    %eax, 287454020
        ret

f2:
        movl    $-1370828758, 287454020
        ret

Aren't both functions syntactically the same, and shouldn't they produce the
same optimized code as in "f2" above? This used to be the case in GCC 4.2.2.

The problem I'm seeing, apart from the lack of optimization, is that "f1"
causes 5 separate writes to a single MMIO register, instead of 1. This
particular hardware register is only expecting one write to this location, and
when multiple writes are received it causes the hardware to fail.

If this new behavior is intended, is there some sort of attribute I can add to
the code to get the original 4.2.2 behavior back?

Thanks,
 -Byron


-- 
           Summary: Problem initializing volatile structures
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gandalf at winds dot org
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


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


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

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

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-29 19:27 [Bug c/42898] New: Problem initializing volatile structures gandalf at winds dot org
2010-01-29 19:38 ` [Bug c/42898] [4.3/4.4/4.5 Regression] volatile structures and compound literals pinskia at gcc dot gnu dot org
2010-01-29 22:42 ` [Bug middle-end/42898] [4.3/4.4/4.5 Regression] volatile structures and compound literal initializers rguenth at gcc dot gnu dot org
2010-01-29 22:42 ` rguenth at gcc dot gnu dot org
2010-01-29 22:42 ` rguenth at gcc dot gnu dot org
2010-01-30 18:09 ` rguenth at gcc dot gnu dot org
2010-01-30 18:17 ` rguenth at gcc dot gnu dot org
2010-01-30 20:56 ` gandalf at winds dot org
2010-01-30 21:25 ` rguenther at suse dot de
2010-01-31 17:02 ` rguenth at gcc dot gnu dot org
2010-01-31 17:04 ` rguenth at gcc dot gnu dot org
2010-01-31 17:07 ` rguenth at gcc dot gnu dot org
2010-01-31 17:09 ` [Bug middle-end/42898] [4.5 " rguenth at gcc dot gnu dot org
2010-01-31 20:01 ` ebotcazou at gcc dot gnu dot org
2010-01-31 21:06 ` ebotcazou at gcc dot gnu dot org
2010-01-31 21:08 ` ebotcazou at gcc dot gnu dot org
2010-02-01  1:47 ` howarth at nitro dot med dot uc dot edu
2010-02-01  1:51 ` howarth at nitro dot med dot uc dot edu
2010-02-01  1:54 ` howarth at nitro dot med dot uc dot edu
2010-02-01  3:13 ` matz at gcc dot gnu dot org
2010-02-02 13:31 ` rguenth at gcc dot gnu dot org
2010-02-05 14:40 ` jamborm at gcc dot gnu dot org
2010-02-08 13:24 ` jamborm at gcc dot gnu dot org
2010-02-08 13:32 ` jamborm 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).