public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/102306] New: Volatile pointer dereferenced twice
@ 2021-09-13 11:59 cederman at gaisler dot com
  2021-09-13 12:14 ` [Bug target/102306] " rguenth at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: cederman at gaisler dot com @ 2021-09-13 11:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102306
           Summary: Volatile pointer dereferenced twice
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cederman at gaisler dot com
                CC: ebotcazou at libertysurf dot fr, segher at kernel dot crashing.org
  Target Milestone: ---

Created attachment 51448
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51448&action=edit
Test case

The following code (full case in attachment) generates two loads from the
volatile "a" pointer on SPARC:

C
  char b = *(volatile unsigned char *)a;
  if (!b)
    return;

Asm
  sethi   %hi(a), %g1
  ld      [%g1+%lo(a)], %g1
  ldub    [%g1], %g2
  ldub    [%g1], %g1
  cmp     %g1, 0

The code is intended to read a memory mapped register that will change after a
read, so two reads will give the wrong value to the comparison.

A bisect showed that this started to happen after "c4c5ad1d6d1e1e1fe7a:
combine: Allow combining two insns to two insns".

The compiler (on commit fc4a29c0781186269dc, latest master at the time) was
configured with:

configure --target=sparc-gaisler-elf --enable-languages=c --disable-nls
--disable-libmudflap --disable-libssp --enable-version-specific-runtime-libs
--disable-fixed-point --disable-decimal-float --disable-shared

and the test was compiled with:

sparc-gaisler-elf -mcpu=v8 -O2

I do not know if this is a generic problem or a SPARC specific one.

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

end of thread, other threads:[~2021-09-17  8:25 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-13 11:59 [Bug rtl-optimization/102306] New: Volatile pointer dereferenced twice cederman at gaisler dot com
2021-09-13 12:14 ` [Bug target/102306] " rguenth at gcc dot gnu.org
2021-09-13 12:17 ` [Bug rtl-optimization/102306] " rguenth at gcc dot gnu.org
2021-09-14 13:25 ` ebotcazou at gcc dot gnu.org
2021-09-14 13:44 ` ebotcazou at gcc dot gnu.org
2021-09-14 13:58 ` ebotcazou at gcc dot gnu.org
2021-09-14 18:35 ` [Bug rtl-optimization/102306] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
2021-09-14 20:20 ` segher at gcc dot gnu.org
2021-09-14 20:23 ` segher at gcc dot gnu.org
2021-09-14 22:52 ` ebotcazou at gcc dot gnu.org
2021-09-15  7:17 ` ebotcazou at gcc dot gnu.org
2021-09-17  8:15 ` cvs-commit at gcc dot gnu.org
2021-09-17  8:19 ` cvs-commit at gcc dot gnu.org
2021-09-17  8:20 ` cvs-commit at gcc dot gnu.org
2021-09-17  8:23 ` cvs-commit at gcc dot gnu.org
2021-09-17  8:25 ` 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).