https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87831
Bug ID: 87831 Summary: Guard variable is not eliminated when there's nothing to guard Product: gcc Version: 9.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: antoshkka at gmail dot com Target Milestone: --- Consider the example: struct base { base() {} }; base& test() { static base val; return val; } For that example a lot of assembly is generated, including empty initialization under the guard: .L14: ; nothing to initialize mov edi, OFFSET FLAT:guard variable for test()::val call __cxa_guard_release mov eax, OFFSET FLAT:_ZZ4testvE3val add rsp, 8 ret Consider removing all the guard variable instructions if there's no instructions for initialization.