From patchwork Mon Sep 12 13:07:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1676968 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=jOB5tTTO; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MR6ND0HKqz1ypL for ; Mon, 12 Sep 2022 23:08:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 63B80385C40E for ; Mon, 12 Sep 2022 13:08:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63B80385C40E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662988085; bh=Ke2+VToL0UPXhejMKBJJrdUn7LkvdEhWa/UDffB5OdU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jOB5tTTOA1DzZf7ayVdbHIeDIzQuBuHR48jUDU7cv3NKG0bA4rJrjm1TVfmsn/FMP rcJoLcHPGynBlaoMSTGkytPwZlq/weSLdFMAFUo1Qs6F4URFR6XfRC6ENJBpzNl2Gp FteEuyYqX9rUqgGxRyjvVIngJTcIaGtbFN1uln2M= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 4A5453856DD6 for ; Mon, 12 Sep 2022 13:07:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4A5453856DD6 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-216-RW9pV3ieNY6y3j5mTCUcsQ-1; Mon, 12 Sep 2022 09:07:36 -0400 X-MC-Unique: RW9pV3ieNY6y3j5mTCUcsQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9FF66101AA64 for ; Mon, 12 Sep 2022 13:07:36 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.194.80]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B60B140EBF3; Mon, 12 Sep 2022 13:07:36 +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 28CD7X9L484138 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 12 Sep 2022 15:07:33 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 28CD7XWO484137; Mon, 12 Sep 2022 15:07:33 +0200 To: GCC patches Subject: [COMMITTED] frange::set_signbit: Avoid changing sign when already in the correct sign. Date: Mon, 12 Sep 2022 15:07:12 +0200 Message-Id: <20220912130711.484083-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" We should avoid pessimizing the signbit when it's already correct. In this particular case we were trying to change the signbit to "unknown", when it was obviously negative. This test is actually slated for removal with my upcoming revamp of the signbit and NAN tracking, per the conversations regarding tristate. The signbit will be removed in favor of keeping track of it in the range itself, and NAN will just be a pair of boolean flags. However, I don't plan to disturb the tree until after Cauldron. Tested on x86-64 Linux including mpfr tests. Also tested selftests with -ffinite-math-only on x86-64 as well as on a cross to pdp11-aout. gcc/ChangeLog: * value-range.cc (frange::set_signbit): Avoid changing sign when already in the correct sign. --- gcc/value-range.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index adcaaa2a69a..6f0609959b3 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -316,9 +316,13 @@ frange::set_signbit (fp_prop::kind k) // Ignore sign changes when they're set correctly. if (!maybe_nan ()) { - if (real_less (&m_max, &dconst0)) + // It's negative and we're trying to make it negative or varying. + if (real_less (&m_max, &dconst0) && (k == fp_prop::YES + || k == fp_prop::VARYING)) return; - if (real_less (&dconst0, &m_min)) + // It's positive and we're trying to make it positive or varying. + if (real_less (&dconst0, &m_min) && (k == fp_prop::NO + || k == fp_prop::VARYING)) return; } // Adjust the range depending on the sign bit.