From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662988059; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Ke2+VToL0UPXhejMKBJJrdUn7LkvdEhWa/UDffB5OdU=; b=HBN4fI42RStQzW6Gfe1S0rnTeFDN5KpR3v3Y5rz5mNd31yc1ddQyv6OWlMkEPDS7jndpWB DhzNLF7loc+20YnSyechY1KPzbDSV29w0y4DD0/nnJuzL7LlHgJDt2dhAbPuPWl3Fer60K uc2DwE8YCXpao+/8bcZ1WDBGcclCCrA= 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 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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. -- 2.37.1