From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E41083858C27; Wed, 24 Nov 2021 13:02:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E41083858C27 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/103406] [12 Regression] gcc -O0 behaves differently on "DBL_MAX related operations" than gcc -O1 and above Date: Wed, 24 Nov 2021 13:02:06 +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.1.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: roger at nextmovesoftware dot com X-Bugzilla-Target-Milestone: 12.0 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: Wed, 24 Nov 2021 13:02:07 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103406 --- Comment #8 from Richard Biener --- And the -nan vs. nan is because we fold x + -y to x - y: /* We can't reassociate at all for saturating types. */ (if (!TYPE_SATURATING (type)) /* Contract negates. */ /* A + (-B) -> A - B */ (simplify (plus:c @0 (convert? (negate @1))) /* Apply STRIP_NOPS on the negate. */ (if (tree_nop_conversion_p (type, TREE_TYPE (@1)) && !TYPE_OVERFLOW_SANITIZED (type)) (with { tree t1 =3D type; if (INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_WRAPS (type) !=3D TYPE_OVERFLOW_WRAPS (TREE_TYPE = (@1))) t1 =3D TYPE_OVERFLOW_WRAPS (type) ? type : TREE_TYPE (@1); } (convert (minus (convert:t1 @0) (convert:t1 @1)))))) all the negate contracting misses HONOR_SIGNED_ZEROS/HONOR_NANS checking? Not sure if they are really a problem for signed zeros? If so we should try to get a testcase for that as well. diff --git a/gcc/match.pd b/gcc/match.pd index 5adcd6bd02c..9cdd113e02c 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2471,7 +2473,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (plus:c @0 (convert? (negate @1))) /* Apply STRIP_NOPS on the negate. */ (if (tree_nop_conversion_p (type, TREE_TYPE (@1)) - && !TYPE_OVERFLOW_SANITIZED (type)) + && !TYPE_OVERFLOW_SANITIZED (type) + && (!FLOAT_TYPE_P (type) || !tree_expr_maybe_nan_p (@1))) (with { tree t1 =3D type; @@ -2484,7 +2487,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (minus @0 (convert? (negate @1))) (if (tree_nop_conversion_p (type, TREE_TYPE (@1)) - && !TYPE_OVERFLOW_SANITIZED (type)) + && !TYPE_OVERFLOW_SANITIZED (type) + && (!FLOAT_TYPE_P (type) || !tree_expr_maybe_nan_p (@1))) (with { tree t1 =3D type; btw, that doesn't fix it since combine will happily contract the negate as well: - 10: {r88:DF=3D-r83:DF;use r89:V2DF;clobber flags:CC;} - REG_DEAD r89:V2DF - REG_UNUSED flags:CC - 11: r90:DF=3Dr88:DF+r83:DF - REG_DEAD r88:DF + 9: NOTE_INSN_DELETED + 10: NOTE_INSN_DELETED + 11: r90:DF=3Dr83:DF-r83:DF=