public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/94836] New: Failure to optimize condition based on known value of static variable
@ 2020-04-28 23:56 gabravier at gmail dot com
  2020-04-29  7:12 ` [Bug tree-optimization/94836] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: gabravier at gmail dot com @ 2020-04-28 23:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94836
           Summary: Failure to optimize condition based on known value of
                    static variable
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

int f(int x)
{
    static int s;

    if (s)
        s = x;

    return s;
}

This can be optimized to `return 0`. This transformation is done by LLVM, but
not by GCC

LLVM -O3 outputs :

f(int): # @f(int)
  xor eax, eax
  ret

GCC -O3 outputs :

f(int):
  mov eax, DWORD PTR f(int)::s[rip]
  test eax, eax
  je .L1
  mov DWORD PTR f(int)::s[rip], edi
  mov eax, edi
.L1:
  ret

(see also https://godbolt.org/z/FzpjCb)

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

end of thread, other threads:[~2021-08-30  5:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-28 23:56 [Bug tree-optimization/94836] New: Failure to optimize condition based on known value of static variable gabravier at gmail dot com
2020-04-29  7:12 ` [Bug tree-optimization/94836] " rguenth at gcc dot gnu.org
2020-04-30  8:09 ` rguenth at gcc dot gnu.org
2020-04-30  8:17 ` rguenth at gcc dot gnu.org
2021-08-30  5:02 ` pinskia 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).