From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 89BF93858C2D; Mon, 13 Nov 2023 12:22:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89BF93858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1699878156; bh=4ce6Y+APbBUjN4gDUOec8Qed8mSOezLf1hDEAkCmwr4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fuAEETr8zVkfZjINo/PbvFYTlao/kv5coGwEVjd5nklw2Fhu+Nq1C0Dq2ARWAx0nb y2r0lTGGm6HSdlPcWlP9VaEJY0GkOnAGe7a4PGEzxvtrSixgQF0lNVmiXwz8FYwshj Q5mFypr+nM2oLn8aSSvKy98RTwXae8MY69eo0iNc= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/112480] optional::reset emits inefficient code when T is trivially-destructible Date: Mon, 13 Nov 2023 12:22:36 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW 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: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D112480 --- Comment #8 from Jonathan Wakely --- Good point, it looks like we get the same codegen improvement for ~T(){} ev= en at -O1 if we don't restrict it to trivially destructible types. There seems to be no difference in codegen for _M_engaged=3Dfalse or _M_engaged=3D_M_engaged (which isn't too surprising, since we know that eit= her it was already false, or we're setting it to false). Given that, I think I pre= fer explicitly setting to false. So I'll test this: --- a/libstdc++-v3/include/std/optional +++ b/libstdc++-v3/include/std/optional @@ -311,6 +311,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { if (this->_M_engaged) _M_destroy(); + else // This seems redundant but improves codegen, see PR 112480. + this->_M_engaged =3D false; } };=