public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105260] Union with user-defined empty destructor leads to worse code-gen Date: Wed, 13 Apr 2022 13:12:35 +0000 [thread overview] Message-ID: <bug-105260-4-yR0AIxNvUX@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-105260-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105260 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org, | |jamborm at gcc dot gnu.org Keywords|ABI, wrong-code | --- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> --- I don't see any ABI differences, nor wrong-code. If you look at *.optimized dump differences, there are pretty much none, except for one extra CLOBBER. But there are 2 differences not visible in the dump. One is that while neither un variable is TREE_ADDRESSABLE, the no WORKAROUND one has TREE_ADDRESSABLE type (as it has non-trivial destructor). The other difference that matters for this testcase is that TYPE_MODE of the NoDestroy union type is BLKmode, while for WORKAROUND=1 case it is DImode. This is both done in: /* If this type has a copy constructor or a destructor, force its mode to be BLKmode, and force its TREE_ADDRESSABLE bit to be nonzero. This will cause it to be passed by invisible reference and prevent it from being returned in a register. */ if (type_has_nontrivial_copy_init (t) || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)) { tree variants; SET_DECL_MODE (TYPE_MAIN_DECL (t), BLKmode); for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants)) { SET_TYPE_MODE (variants, BLKmode); TREE_ADDRESSABLE (variants) = 1; } } Now, for the ABI passing the above is really required, such types are indeed passed differently from ones that have trivialy copy ctor and dtor, but for this testcase it is just an optimization decision (use_register_for_decl). We do there: /* Only register-like things go in registers. */ if (DECL_MODE (decl) == BLKmode) return false; Guess we'd need to recompute mode for non-TREE_ADDRESSABLE vars before expansion. Or find out why SRA doesn't optimize this (remove the useless union, replace all the un.value occurrences with a var with Foo type.
next prev parent reply other threads:[~2022-04-13 13:12 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-13 9:39 [Bug c++/105260] New: " m.cencora at gmail dot com 2022-04-13 12:10 ` [Bug c++/105260] " rguenth at gcc dot gnu.org 2022-04-13 12:13 ` rguenth at gcc dot gnu.org 2022-04-13 12:15 ` rguenth at gcc dot gnu.org 2022-04-13 12:16 ` m.cencora at gmail dot com 2022-04-13 12:19 ` m.cencora at gmail dot com 2022-04-13 12:26 ` m.cencora at gmail dot com 2022-04-13 13:12 ` jakub at gcc dot gnu.org [this message] 2022-04-13 16:08 ` jamborm at gcc dot gnu.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-105260-4-yR0AIxNvUX@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: linkBe 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).