From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EE5DF3858405; Tue, 31 Aug 2021 07:12:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE5DF3858405 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/102129] -ftrapping-math is broken or badly documented Date: Tue, 31 Aug 2021 07:12:32 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.2.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: everconfirmed bug_status cf_reconfirmed_on keywords assigned_to 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: Tue, 31 Aug 2021 07:12:33 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102129 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Status|UNCONFIRMED |ASSIGNED Last reconfirmed| |2021-08-31 Keywords| |wrong-code Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot = gnu.org --- Comment #4 from Richard Biener --- For the testcase in the description it's TER that causes code motion of the possibly trapping expression. ssa_is_replaceable_p already tests stmt_could_throw_p (that's including externally throwing) but fails to check for traps. In principle code motion would need to be restricted only up to the next stmt that possibly terminates and only if we are supposed to prese= rve (the order of) traps and external throwing stmts (with respect to possible observers). The question is whether it is important to preserve as much TER as possible (for optimization purposes). If that's not the case then the following fix= es this bug. diff --git a/gcc/tree-outof-ssa.c b/gcc/tree-outof-ssa.c index 1a133a09177..484f401ce68 100644 --- a/gcc/tree-outof-ssa.c +++ b/gcc/tree-outof-ssa.c @@ -64,8 +64,10 @@ ssa_is_replaceable_p (gimple *stmt) if (!is_gimple_assign (stmt)) return false; - /* If the statement may throw an exception, it cannot be replaced. */ - if (stmt_could_throw_p (cfun, stmt)) + /* If the statement may throw an exception or it could trap, + it cannot be replaced. */ + if (stmt_could_throw_p (cfun, stmt) + || gimple_could_trap_p (stmt)) return false; /* Punt if there is more than 1 def. */=