From patchwork Mon Aug 29 20:44:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 57152 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 DFF2F3856960 for ; Mon, 29 Aug 2022 20:45:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFF2F3856960 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661805918; bh=R+HYMM6T4b73rde2LQ9KH8rmPmeHdLIXDWYXNFWzrDA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FlnUmJBR7O95Ng43ATvE+ecE4L0o8Fl23DWoEwT05KCjKm88h8FCGr7vfOOC5f5W6 MKUSO5/xnzPeFcLcNoPXQiU6SfKwrjruV40tGahj6IBdSKbzxybOePSJi6p1iB0L+b qnMCJWnnSFKFSq+nJeoPauQXVid53lnYXMNi81rQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0F351385AC3F for ; Mon, 29 Aug 2022 20:44:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0F351385AC3F Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-557-_33jBQzvNVGkyeFH3M5cVw-1; Mon, 29 Aug 2022 16:44:45 -0400 X-MC-Unique: _33jBQzvNVGkyeFH3M5cVw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9878A85A589 for ; Mon, 29 Aug 2022 20:44:45 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.85]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4DC9E2026D4C; Mon, 29 Aug 2022 20:44:45 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 27TKig5d1749742 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 29 Aug 2022 22:44:42 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 27TKigdr1749741; Mon, 29 Aug 2022 22:44:42 +0200 To: GCC patches Subject: [PATCH] A == 0 ? A : -A same as -A (when A is 0.0) Date: Mon, 29 Aug 2022 22:44:39 +0200 Message-Id: <20220829204439.1749727-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The upcoming work for frange triggers a regression in gcc.dg/tree-ssa/phi-opt-24.c. For -O2 -fno-signed-zeros, we fail to transform the following into -A: float f0(float A) { // A == 0? A : -A same as -A if (A == 0) return A; return -A; } This is because the abs/negative match.pd pattern here: /* abs/negative simplifications moved from fold_cond_expr_with_comparison, Need to handle (A - B) case as fold_cond_expr_with_comparison does. Need to handle UN* comparisons. ... ... Sees IL that has the 0.0 propagated. Instead of: [local count: 1073741824]: if (A_2(D) == 0.0) goto ; [34.00%] else goto ; [66.00%] [local count: 708669601]: _3 = -A_2(D); [local count: 1073741824]: # _1 = PHI It now sees: [local count: 1073741824]: # _1 = PHI <0.0(2), _3(3)> which it leaves untouched, causing the if conditional to survive. Adding a variant to the pattern that for real_zerop fixes the problem. I am a match.pd weenie, and am avoiding touching more patterns that may also benefit from handling real constants. So please use simple words if what I'm doing isn't correct ;-). I did not include a testcase, as it's just phi-opt-24.c which will get triggered when I commit the frange with endpoints work. Tested on x86-64 & ppc64le Linux. OK? gcc/ChangeLog: * match.pd ((cmp @0 zerop) real_zerop (negate@1 @0)): Add variant for real zero. --- gcc/match.pd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index 1bb936fc401..5bdea300f94 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4803,6 +4803,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cnd (cmp @0 zerop) @0 (negate@1 @0)) (if (!HONOR_SIGNED_ZEROS (type)) @1)) + (simplify + (cnd (cmp @0 zerop) real_zerop (negate@1 @0)) + (if (!HONOR_SIGNED_ZEROS (type)) + @1)) (simplify (cnd (cmp @0 zerop) integer_zerop (negate@1 @0)) (if (!HONOR_SIGNED_ZEROS (type))