https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118132
Bug ID: 118132 Summary: Vectorize optimization generates obsolete code, which causes significant performance drop Product: gcc Version: 11.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: German.Andryeyev at amd dot com Target Milestone: --- Created attachment 59926 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59926&action=edit A C++ sample that exposes a problem with tree-vectorize optimization - The attached zip file contains a trivial program(main.cpp, dispatch.cpp, dispatch.hpp) and a script to compile the program (build.sh) - The script accepts 2 options 0 and 1. 0 - disables vectorize for one function and 1 - enables - The portion of the code that will disable tree-vectorize #if !VECTORIZE __attribute__((optimize("no-tree-vectorize"))) #endif const DispatchTable* GetDispatchTable() { static auto* _v = &GetDispatchTableImpl<DispatchTable>(); return _v; } - The issue: compiler adds extra instructions which will fill the struct on the stack unconditionally for every invocation of GetDispatchTable() and then drops that.