From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 61EE13898C73; Mon, 5 Dec 2022 10:55:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61EE13898C73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670237735; bh=lditAxCQgjkvHYVygMnxBw1naH7XoEcq+Qp6WncY0dQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=mh2lapVIMQACwGsQcOcJ4eB9twwha28M56/iZCAUkkjvwM1bx0StyEzSDqa6tbHUi VTrDAblzdXSxh26OqqXJX3wPsfH1D0vxbgS2hR9TqjUJMJdw/SFNYtTN1V5sDYlNNF ymJvHEuDaPrnblw92Xi9tU+4r0PXFSRJQQrS0rgc= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/106805] [13 Regression] Undue optimisation of floating-point comparisons Date: Mon, 05 Dec 2022 10:55:33 +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: 13.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit 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: 13.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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106805 --- Comment #5 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:109148dd16e4bcd50faee19c49082de69d0ba26e commit r13-4493-g109148dd16e4bcd50faee19c49082de69d0ba26e Author: Jakub Jelinek Date: Mon Dec 5 11:54:45 2022 +0100 match.pd: Don't fold nan < x etc. for -ftrapping-math [PR106805] As reported in the PR, the following pr106805.c testcase is miscompiled with the default -ftrapping-math, because we fold all the comparisons i= nto constants and don't raise any exceptions. The match.pd pattern handles just simple comparisons, from those EQ/NE are quiet and don't raise exceptions on anything but sNaN, while GT/GE/LT/LE are signaling and do raise exceptions even on qNaN. fold_relational_const handles this IMHO correctly: /* Handle the cases where either operand is a NaN. */ if (real_isnan (c0) || real_isnan (c1)) { switch (code) { case EQ_EXPR: case ORDERED_EXPR: result =3D 0; break; case NE_EXPR: case UNORDERED_EXPR: case UNLT_EXPR: case UNLE_EXPR: case UNGT_EXPR: case UNGE_EXPR: case UNEQ_EXPR: result =3D 1; break; case LT_EXPR: case LE_EXPR: case GT_EXPR: case GE_EXPR: case LTGT_EXPR: if (flag_trapping_math) return NULL_TREE; result =3D 0; break; default: gcc_unreachable (); } return constant_boolean_node (result, type); } by folding the signaling comparisons only if -fno-trapping-math. The following patch does the same in match.pd. Unfortunately the pr106805.c testcase still fails, but no longer becaus= e of match.pd, but on the trunk because of the still unresolved ranger probl= ems (same issue as for fold-overflow-1.c etc.) and on 12 branch (and presum= ably trunk too) somewhere during expansion the comparisons are also expanded into constants (which is ok for -fno-trapping-math, but not ok with tha= t). Though, I think the patch is a small step in the direction, so I'd like to commit this patch without the gcc.dg/pr106805.c testcase for now. 2022-12-05 Jakub Jelinek PR middle-end/106805 * match.pd (cmp=C2=A0@0=C2=A0REAL_CST@1): Don't optimize x cmp = NaN or NaN cmp x to false/true for cmp >/>=3D/