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)