From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 38F1C3AA9412; Thu, 8 Jul 2021 14:09:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38F1C3AA9412 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/100409] C++ FE elides pure throwing call Date: Thu, 08 Jul 2021 14:09:02 +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: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth 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: 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: Thu, 08 Jul 2021 14:09:02 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100409 --- Comment #14 from Richard Biener --- (In reply to Jason Merrill from comment #13) > (In reply to Richard Biener from comment #3) > > - if (! TREE_SIDE_EFFECTS (expr)) > > + if (! TREE_SIDE_EFFECTS (expr) && expr_noexcept_p (expr, 0)) > > expr =3D void_node; >=20 > The assumption that an expression with TREE_SIDE_EFFECTS unset can be > discarded if its value is not used is made throughout the compiler.=20 > Abandoning that invariant seems like a bad idea. And changing from check= ing > a flag to walking through the whole expression in all of those places sou= nds > like an algorithmic complexity problem. >=20 > If a pure/const function can throw, fine. But that shouldn't affect how > optimization treats the function call, or we'll end up pessimizing the va= st > majority of calls to pure/const functions that don't throw (but are not > explicitly declared noexcept). In this testcase, if the user doesn't want > the compiler to optimize away a call to foo(), they shouldn't mark it pur= e. Hmm, fair enough. Does that mean C++ should default to -fdelete-dead-exceptions? Elsewhere it's said that TREE_SIDE_EFFECTS, const/pure and EH are orthogonal concepts but yes, that we have to walk expressions recursively to figure nothrow sucks. Though the convert_to_void "optimization" could be seen as premature, on GIMPLE there's no recursive walking needed and nothrow discovery should discover nothrow-ness of most small functions that have the body available - so the other option I considered was to remove that optimization. Now, this C++ decision makes my life a bit harder (writing testcases for the middle-end issues around throwing pure/const functions).=