public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "i at maskray dot me" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/19661] unnecessary atexit calls emitted for static objects with empty destructors
Date: Sat, 16 Mar 2024 22:47:01 +0000	[thread overview]
Message-ID: <bug-19661-4-ht9b8xkBBH@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-19661-4@http.gcc.gnu.org/bugzilla/>

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.

  parent reply	other threads:[~2024-03-16 22:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-19661-4@http.gcc.gnu.org/bugzilla/>
2021-09-24  7:41 ` antoshkka at gmail dot com
2022-11-02 15:47 ` pinskia at gcc dot gnu.org
2022-11-02 15:53 ` redi at gcc dot gnu.org
2022-11-02 17:16 ` redi at gcc dot gnu.org
2024-03-15 22:56 ` pinskia at gcc dot gnu.org
2024-03-15 23:40 ` pinskia at gcc dot gnu.org
2024-03-16  2:17 ` pinskia at gcc dot gnu.org
2024-03-16 22:47 ` i at maskray dot me [this message]
2024-04-19  0:39 ` pinskia at gcc dot gnu.org
2024-04-19  0:59 ` pinskia at gcc dot gnu.org
2024-05-07 21:47 ` cvs-commit at gcc dot gnu.org
2024-05-07 21:47 ` pinskia at gcc dot gnu.org
     [not found] <bug-19661-6649@http.gcc.gnu.org/bugzilla/>
2008-02-20 21:53 ` pinskia at gcc dot gnu dot org
2005-01-27 22:24 [Bug c++/19661] New: many redundant atexit calls emitted into the executable " yuri at tsoft dot com
2005-09-24 17:43 ` [Bug tree-optimization/19661] unnecessary atexit calls emitted " pinskia at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-19661-4-ht9b8xkBBH@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).