https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19661
Fangrui Song <i at maskray dot me> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |i at maskray dot me --- Comment #17 from Fangrui Song <i at maskray dot me> --- (In reply to Andrew Pinski from comment #16) > So what is interesting is the way LLVM implements this as an IPO pass as how > I described in comment #8, 6 years after I wrote that. Well they used > "empty" rather than const . Note using it as an IPO pass I think is not > wrong just having a specialized pass here where this is the same as DCE so > just have DCE handle it instead seems better; plus with the availability of > having pure/const flags with LTO and not having to load in the function > seems much better really. Yes, LLVM recognizes __cxa_atexit as a library function and removes it in GlobalOpt (part of IPO) since 2011 (https://github.com/llvm/llvm-project/commit/ee6bc70d2f1c2434ca9ca8092216bdeab322c7e5), likely because GlobalOpt is already doing global variable optimizations (e.g. removal if dead, constant folding). Technically __cxa_atexit removal can be moved elsewhere. There are two GlobalOpt passes in the optimization pipeline (see -mllvm -print-changed=cdiff output), one before the inliner and one after. SROA ... GlobalOpt ... buildInlinerPipeline ... GlobalOpt For empty functions like `~constant_init() {}`, SROA deletes unneeded IR instructions (spill of the "this" pointer) and actually makes the IR function empty. Then GlobalOpt removes __cxa_atexit call sites. For `static void empty() {} ~constant_init() { empty(); }`, the inliner removes the `empty()` and makes the IR function empty. Then GlobalOpt removes __cxa_atexit call sites.