public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/63991] New: redundant read when write to volatile member of packed structure
@ 2014-11-20 11:07 potrepalov@asc-ural.ru
  2014-11-20 12:06 ` [Bug middle-end/63991] " rguenth at gcc dot gnu.org
  2014-11-22 11:58 ` ebotcazou at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: potrepalov@asc-ural.ru @ 2014-11-20 11:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63991

            Bug ID: 63991
           Summary: redundant read when write to volatile member of packed
                    structure
           Product: gcc
           Version: 4.8.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: potrepalov@asc-ural.ru

There is redundant read when write to volatile member of packed structure:

exti.c:
---------------
typedef struct
{
  volatile unsigned int IMR;
  volatile unsigned int EMR;
  volatile unsigned int RTSR;
  volatile unsigned int FTSR;
  volatile unsigned int SWIER;
  volatile unsigned int PR;
} EXTI_TypeDef;

void
EXTI_5_IRQHandler( EXTI_TypeDef * exti ) { exti->PR = 1 << 5; }
---------------


make.bat:
---------------
arm-none-eabi-gcc -mthumb -march=armv7e-m -fpack-struct -O2 -c exti.c -o
exti-bug.o
arm-none-eabi-gcc -mthumb -march=armv7e-m               -O2 -c exti.c -o exti.o

arm-none-eabi-objdump -a -S exti.o > exti.lst
arm-none-eabi-objdump -a -S exti-bug.o > exti-bug.lst
---------------


exti.lst
---------------
exti.o:     file format elf32-littlearm
exti.o


Disassembly of section .text:

00000000 <EXTI_5_IRQHandler>:
   0:    2320          movs    r3, #32
   2:    6143          str    r3, [r0, #20]
   4:    4770          bx    lr
   6:    bf00          nop
----------------


exti-bug.lst
----------------
exti-bug.o:     file format elf32-littlearm
exti-bug.o


Disassembly of section .text:

00000000 <EXTI_5_IRQHandler>:
   0:    2320          movs    r3, #32
   2:    6942          ldr    r2, [r0, #20]
   4:    6143          str    r3, [r0, #20]
   6:    4770          bx    lr
----------------


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

* [Bug middle-end/63991] redundant read when write to volatile member of packed structure
  2014-11-20 11:07 [Bug c/63991] New: redundant read when write to volatile member of packed structure potrepalov@asc-ural.ru
@ 2014-11-20 12:06 ` rguenth at gcc dot gnu.org
  2014-11-22 11:58 ` ebotcazou at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-11-20 12:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63991

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |arm-none-eabi
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-11-20
                 CC|                            |ebotcazou at gcc dot gnu.org
          Component|c                           |middle-end
     Ever confirmed|0                           |1
      Known to fail|                            |5.0

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
That's indeed a bug as if the structure is unaligned (which is what happens
with -fpack-struct).  Correct code looks like

        mov     r2, #32
        mov     r3, #0
        ldrb    r1, [r0, #20]   @ zero_extendqisi2
        strb    r2, [r0, #20]
        ldrb    r2, [r0, #21]   @ zero_extendqisi2
        strb    r3, [r0, #21]
        ldrb    r2, [r0, #22]   @ zero_extendqisi2
        strb    r3, [r0, #22]
        ldrb    r2, [r0, #23]   @ zero_extendqisi2
        strb    r3, [r0, #23]

but still for some reason we create volatile unused loads at expansion time
(and those prevail and don't get DCEd, obviously).

Probably happens on all strict-alignment targets.


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

* [Bug middle-end/63991] redundant read when write to volatile member of packed structure
  2014-11-20 11:07 [Bug c/63991] New: redundant read when write to volatile member of packed structure potrepalov@asc-ural.ru
  2014-11-20 12:06 ` [Bug middle-end/63991] " rguenth at gcc dot gnu.org
@ 2014-11-22 11:58 ` ebotcazou at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2014-11-22 11:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63991

--- Comment #2 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
It looks like -fpack-struct cannot be used when -fstrict-volatile-bitfields is
in effect, i.e. on ARM EABI.  As for unaligned volatile fields on
strict-alignment
targets, they clearly ask for trouble.  Simply do not use -fpack-struct.


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

end of thread, other threads:[~2014-11-22 11:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-20 11:07 [Bug c/63991] New: redundant read when write to volatile member of packed structure potrepalov@asc-ural.ru
2014-11-20 12:06 ` [Bug middle-end/63991] " rguenth at gcc dot gnu.org
2014-11-22 11:58 ` ebotcazou 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).