From patchwork Thu Nov 25 11:29:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 48126 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AF6DE3858004 for ; Thu, 25 Nov 2021 11:30:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 8BAF33858038 for ; Thu, 25 Nov 2021 11:29:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8BAF33858038 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=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:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=LDiKXPfMiQ0Tk/6HYGcyVVf1Q62GPBwUjUe3BJZsTtE=; b=MgbcigJZo6f26cZ80AdE++B1AR U0i/afQP8Srr5an/n5VtJkz1c9kvhFcbEoQw0SbrzflmMEdzKQhM3UUq80y+6+uq41+nGBVvLYa5Q kEKB+e2xRl866ECKijhENJi0GYB5ZvHXNjCZdARralcEqo0Dr3JDE43mujFTw6iEyje5rttvTlN0T vIbsuxZnBT72xKh6ltAPEJ4fapcRpqtxT1rmY+VPK49YojKqORCNszjmPsXZzBZj/lFf9sKOvD8gJ YMi62h+s/vDZh80arvO8t1WczKjAcVTmwV3EyrG5tHatUezKsY3MgkUnK1YLKOT1+i1QZvsnfKhg+ rd2Mk53w==; Received: from host81-157-90-156.range81-157.btcentralplus.com ([81.157.90.156]:52854 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mqCwZ-0000LM-Ta for gcc-patches@gcc.gnu.org; Thu, 25 Nov 2021 06:29:36 -0500 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] PR middle-end/103406: Check for Inf before simplifying x-x. Date: Thu, 25 Nov 2021 11:29:32 -0000 Message-ID: <02cd01d7e1ef$b8b17570$2a146050$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adfh7yBU0VHa5fKMRiiO9XF+QXf0XA== 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=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This is a simple one line fix to the regression PR middle-end/103406, where x - x is being folded to 0.0 even when x is +Inf or -Inf. In GCC 11 and previously, we'd check whether the type honored NaNs (which implicitly covered the case where the type honors infinities), but my patch to test whether the operand could potentially be NaN failed to also check whether the operand could potentially be Inf. This patch doesn't address the issue of NaN signedness from binary arithmetic operations, just the regression. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check with no new failures. Ok for mainline? 2021-11-25 Roger Sayle gcc/ChangeLog PR middle-end/103406 * match.pd (minus @0 @0): Check tree_expr_maybe_infinite_p. gcc/testsuite/ChangeLog PR middle-end/103406 * gcc.dg/pr103406.c: New test case. Thanks in advance (and sorry for the inconvenience), Roger diff --git a/gcc/match.pd b/gcc/match.pd index f059b47..d28dfe2 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -232,7 +232,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) is volatile. */ (simplify (minus @0 @0) - (if (!FLOAT_TYPE_P (type) || !tree_expr_maybe_nan_p (@0)) + (if (!FLOAT_TYPE_P (type) + || (!tree_expr_maybe_nan_p (@0) + && !tree_expr_maybe_infinite_p (@0))) { build_zero_cst (type); })) (simplify (pointer_diff @@0 @0) diff --git a/gcc/testsuite/gcc.dg/pr103406.c b/gcc/testsuite/gcc.dg/pr103406.c new file mode 100644 index 0000000..9c7b83b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr103406.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#define HUGE __DBL_MAX__ +#define INF (HUGE + HUGE) +#define NAN (INF - INF) + +double foo() { + double x = -NAN; + double y = NAN; + return x + y; +} + +/* { dg-final { scan-tree-dump-not "return 0\.0" "optimized" } } */