From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3BDB8385734A; Wed, 13 Apr 2022 13:12:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3BDB8385734A From: "jakub at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc keywords Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Apr 2022 13:12:35 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105260 Jakub Jelinek 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 --- I don't see any ABI differences, nor wrong-code. If you look at *.optimized dump differences, there are pretty much none, ex= cept 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=3D1 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 =3D t; variants; variants =3D TYPE_NEXT_VARIANT (varian= ts)) { SET_TYPE_MODE (variants, BLKmode); TREE_ADDRESSABLE (variants) =3D 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) =3D=3D 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.=