From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id E91F3397183A for ; Fri, 27 Nov 2020 10:56:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E91F3397183A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=roger@nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:In-Reply-To:References:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=VRC9M0zjn1Uy0Dh5BCW7fS4N23M4xjHt8k9OHYPa30k=; b=SC9zvftnJxlwljeKuZcHfie8n KNiRyDAMGS2OONoVytAW7fZO700jmce/EqZYAUb/K2PvALTwU5/ZNZCNBm9+g1dL+W9KwIeI9tVDk cYCkxdS+IJ4UKXlWEVXWvyM6KYeRI/szocWQuULqewIuIbFAN2DkWHv5V/kjYc0iNHyNqpHKMVb1y kSpxvZTbK6RN6dOdPN7fPvjsQmAPIp6XLr6db5llFvJ4hwv9MPYlndFIKwWKh75Fla98Fi7XYBeGD 5WH3UrOXEjZQQ2s1sqNDzg2wCKoE6663mRJc8paAHHX/RKBMvZtvAstWujWcqhu6xAcm3rDoeMc29 lxpDXjAJQ==; Received: from host86-148-67-112.range86-148.btcentralplus.com ([86.148.67.112]:63674 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kibQT-0005bP-T6; Fri, 27 Nov 2020 05:56:30 -0500 From: "Roger Sayle" To: "'Jakub Jelinek'" , "'Joseph S. Myers'" Cc: "'Richard Biener'" , References: <20201126083155.GN3788@tucnak> <20201126094903.GV3788@tucnak> <02b501d6c3fb$e248fc90$a6daf5b0$@nextmovesoftware.com> <20201126224304.GD3788@tucnak> In-Reply-To: Subject: RE: [PATCH] fold-const: Don't consider NaN non-negative [PR97965] Date: Fri, 27 Nov 2020 10:56:29 -0000 Message-ID: <032501d6c4ab$f6cbee60$e463cb20$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0326_01D6C4AB.F6CC6390" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQLL5N5q6NtZ9ly9leL4d+phv6886wJdci8XAn4rGigBsUZ6ygFcKY5IAYScagEBsF2IYKeYnbQw Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Nov 2020 10:56:32 -0000 This is a multipart message in MIME format. ------=_NextPart_000_0326_01D6C4AB.F6CC6390 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Doh! Wrong patch2.txt file. Sorry. -----Original Message----- From: Roger Sayle Sent: 27 November 2020 10:52 To: 'Jakub Jelinek' ; 'Joseph S. Myers' Cc: 'Richard Biener' ; 'gcc-patches@gcc.gnu.org' Subject: RE: [PATCH] fold-const: Don't consider NaN non-negative [PR97965] Hi Jakub, Technically, PR97965 doesn't explicitly mention equality/inequality, but you're right, it makes sense to tackle this missed optimization at the same time as we fix the wrong-code. On Thu, Nov 26, 2020, Jakub Jelinek wrote: >On Thu, Nov 26, 2020 at 01:56:03PM -0000, Roger Sayle wrote: >> --- a/gcc/match.pd >> +++ b/gcc/match.pd >> @@ -3998,7 +3998,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) >> (cmp @0 { build_real (TREE_TYPE (@1), dconst0); })) >> /* x != NaN is always true, other ops are always false. */ >> (if (REAL_VALUE_ISNAN (TREE_REAL_CST (@1)) >> - && ! HONOR_SNANS (@1)) >> + && ! flag_trapping_math) > >Shouldn't this one stay as is for cmp == EQ_EXPR || cmp == NE_EXPR? >I mean, == or != only raise exceptions on sNaNs, while other simple comparisons raise on both sNaNs and qNaNs. The case to be careful of here is that (x == qNaN) can still raise/trap if x is a sNaN. Hence, the full condition should include: && (!flag_trapping_math || ((cmp == EQ_EXPR || cmp == NE_EXPR) && !tree_expr_maybe_signaling_nan_p (@1) && !tree_expr_maybe_signaling_nan_p (@0))) Note: I repeat tree_expr_maybe_signaling_nan_p here for symmetry, though because we know @1 is a NaN, this could have been written as !tree_expr_signaling_nan_p (@1). >> --- a/gcc/simplify-rtx.c >> +++ b/gcc/simplify-rtx.c >> @@ -5732,12 +5732,13 @@ simplify_const_relational_operation (enum rtx_code code, >> if (REAL_VALUE_ISNAN (*d0) || REAL_VALUE_ISNAN (*d1)) >> switch (code) >> { >> + case NE: >> + return flag_trapping_math ? 0 : const_true_rtx; > > And here too (for NE and would need moving EQ later too. Yep/Agreed. These cases become: case NE: if (flag_trapping_math && (REAL_VALUE_ISSIGNALING_NAN (*d0) || REAL_VALUE_ISSIGANLING_NAN (*d1))) return 0; return const_true_rtx; case EQ: if (flag_trapping_math && (REAL_VALUE_ISSIGNALING_NAN (*d0) || REAL_VALUE_ISSIGANLING_NAN (*d1))) return 0; return const0_rtx; A revised patch is attached (which I've confirmed compiles but haven't regression tested). Many thanks again. Roger -- ------=_NextPart_000_0326_01D6C4AB.F6CC6390 Content-Type: text/plain; name="patch2.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patch2.txt" diff --git a/gcc/fold-const.c b/gcc/fold-const.c=0A= index 632a241a964..b76e80c02a3 100644=0A= --- a/gcc/fold-const.c=0A= +++ b/gcc/fold-const.c=0A= @@ -12007,8 +12007,8 @@ fold_binary_loc (location_t loc, enum tree_code = code, tree type,=0A= strict_overflow_p =3D false;=0A= if (code =3D=3D GE_EXPR=0A= && (integer_zerop (arg1)=0A= - || (! HONOR_NANS (arg0)=0A= - && real_zerop (arg1)))=0A= + || (real_zerop (arg1)=0A= + && !tree_expr_maybe_nan_p (arg0)))=0A= && tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p))=0A= {=0A= if (strict_overflow_p)=0A= @@ -12024,7 +12024,10 @@ fold_binary_loc (location_t loc, enum tree_code = code, tree type,=0A= /* Convert ABS_EXPR < 0 to false. */=0A= strict_overflow_p =3D false;=0A= if (code =3D=3D LT_EXPR=0A= - && (integer_zerop (arg1) || real_zerop (arg1))=0A= + && (integer_zerop (arg1)=0A= + || (real_zerop (arg1)=0A= + && (!flag_trapping_math=0A= + || !tree_expr_maybe_nan_p (arg0))))=0A= && tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p))=0A= {=0A= if (strict_overflow_p)=0A= diff --git a/gcc/match.pd b/gcc/match.pd=0A= index b6dfc24af88..ef1bfb42d12 100644=0A= --- a/gcc/match.pd=0A= +++ b/gcc/match.pd=0A= @@ -4037,7 +4037,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)=0A= (cmp @0 { build_real (TREE_TYPE (@1), dconst0); }))=0A= /* x !=3D NaN is always true, other ops are always false. */=0A= (if (REAL_VALUE_ISNAN (TREE_REAL_CST (@1))=0A= - && ! HONOR_SNANS (@1))=0A= + && (!flag_trapping_math=0A= + || ((cmp =3D=3D EQ_EXPR || cmp =3D=3D NE_EXPR)=0A= + && !tree_expr_maybe_signaling_nan_p (@1)=0A= + && !tree_expr_maybe_signaling_nan_p (@0))))=0A= { constant_boolean_node (cmp =3D=3D NE_EXPR, type); })=0A= /* Fold comparisons against infinity. */=0A= (if (REAL_VALUE_ISINF (TREE_REAL_CST (@1))=0A= diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c=0A= index 47e7aebda8a..dd97a353bff 100644=0A= --- a/gcc/simplify-rtx.c=0A= +++ b/gcc/simplify-rtx.c=0A= @@ -5732,20 +5732,31 @@ simplify_const_relational_operation (enum = rtx_code code,=0A= if (REAL_VALUE_ISNAN (*d0) || REAL_VALUE_ISNAN (*d1))=0A= switch (code)=0A= {=0A= + case NE:=0A= + if (flag_trapping_math=0A= + && (REAL_VALUE_ISSIGNALING_NAN (*d0)=0A= + || REAL_VALUE_ISSIGNALING_NAN (*d1)))=0A= + return 0;=0A= + return const_true_rtx;=0A= case UNEQ:=0A= case UNLT:=0A= case UNGT:=0A= case UNLE:=0A= case UNGE:=0A= - case NE:=0A= case UNORDERED:=0A= return const_true_rtx;=0A= case EQ:=0A= + if (flag_trapping_math=0A= + && (REAL_VALUE_ISSIGNALING_NAN (*d0)=0A= + || REAL_VALUE_ISSIGNALING_NAN (*d1)))=0A= + return 0;=0A= + return const0_rtx;=0A= case LT:=0A= case GT:=0A= case LE:=0A= case GE:=0A= case LTGT:=0A= + return flag_trapping_math ? 0 : const0_rtx;=0A= case ORDERED:=0A= return const0_rtx;=0A= default:=0A= ------=_NextPart_000_0326_01D6C4AB.F6CC6390--