public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/105728] New: dead store to static var not optimized out
@ 2022-05-25 14:14 felix-gcc at fefe dot de
  2022-05-25 16:21 ` Jan Hubicka
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: felix-gcc at fefe dot de @ 2022-05-25 14:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105728
           Summary: dead store to static var not optimized out
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: felix-gcc at fefe dot de
  Target Milestone: ---

Consider this piece of test code:

int dummy1()
{
  static int removeme = 0;
  if (removeme)
  {
      return 0;
  }
  removeme = 1;
  return 0;
}

int dummy2()
{
  static int removeme = 0;
  if (!removeme)
    removeme = 1;
  return 0;
}

int dummy3()
{
  static int removeme = 0;
  removeme = 1;
  return 0;
}

To me, all of these do the same thing and should generate the same code.
As nobody else can see removeme, and we aren't leaking its address, shouldn't
the compiler be able to deduce that all accesses to removeme are
inconsequential and can be removed?

My gcc 11.3 generates a condidion and a store and a return 0 for dummy1, the
same thing for dummy2, but for dummy3 it understands that it only needs to emit
a return 0.

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

end of thread, other threads:[~2022-05-27 13:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-25 14:14 [Bug c/105728] New: dead store to static var not optimized out felix-gcc at fefe dot de
2022-05-25 16:21 ` Jan Hubicka
2022-05-25 16:21 ` [Bug c/105728] " hubicka at kam dot mff.cuni.cz
2022-05-27  6:25 ` [Bug ipa/105728] " rguenth at gcc dot gnu.org
2022-05-27 12:24 ` rguenth at gcc dot gnu.org
2022-05-27 13:16 ` felix-gcc at fefe dot de

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).