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.129.124]) by sourceware.org (Postfix) with ESMTPS id 7049E3858438 for ; Wed, 9 Nov 2022 17:22:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7049E3858438 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=1668014548; 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=+J3M4NnfaqZCKT4thcxu4+LYdg5s4zk4AqI1uLuqP/8=; b=NQ/C9+KNDLtDvsZ68oq0ZIqvSxMYRrGnPHhMY170jBV657lRpXrZouCzXH4VcMIKTgEO1f uXG86m+n/mlctKHaaHe+qf6j/uC8QKLu7yw09CGWt5DrffJWGAVFEL0D7q1DCOP6UzbQHL hh3lg8XLd7JMflG4088AkvcIzPJSWwc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-621-Ct5EqYydMoSVSw1Lj4FK6w-1; Wed, 09 Nov 2022 12:22:24 -0500 X-MC-Unique: Ct5EqYydMoSVSw1Lj4FK6w-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 425593850EAA for ; Wed, 9 Nov 2022 17:22:24 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.11]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CF9FD2028E90; Wed, 9 Nov 2022 17:22:23 +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 2A9HMLwI041372 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 9 Nov 2022 18:22:21 +0100 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 2A9HMLwP041371; Wed, 9 Nov 2022 18:22:21 +0100 From: Aldy Hernandez To: GCC patches Cc: Jakub Jelinek , Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] Clear NAN when reading back a global range if necessary. Date: Wed, 9 Nov 2022 18:21:48 +0100 Message-Id: <20221109172148.41333-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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: When reading back from the global store, we must clear the NAN bit if necessary. The reason it's not happening is because the constructor sets a NAN by default (when HONOR_NANS). We must be careful to clear the NAN bit if the original range didn't have a NAN. I have commented the reason we use the constructor instead of filling out the fields by hand, because it wasn't clear at re-reading this code. PR 107569/tree-optimization gcc/ChangeLog: * value-range-storage.cc (frange_storage_slot::get_frange): Clear NAN if appropriate. * value-range.cc (range_tests_floats): New test. --- gcc/value-range-storage.cc | 9 ++++++++- gcc/value-range.cc | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc index 462447ba250..b57701f0ea1 100644 --- a/gcc/value-range-storage.cc +++ b/gcc/value-range-storage.cc @@ -276,13 +276,20 @@ frange_storage_slot::get_frange (frange &r, tree type) const return; } - // Use the constructor because it will canonicalize the range. + // We use the constructor to create the new range instead of writing + // out the bits into the frange directly, because the global range + // being read may be being inlined into a function with different + // restrictions as when it was originally written. We want to make + // sure the resulting range is canonicalized correctly for the new + // consumer. r = frange (type, m_min, m_max, m_kind); // The constructor will set the NAN bits for HONOR_NANS, but we must // make sure to set the NAN sign if known. if (HONOR_NANS (type) && (m_pos_nan ^ m_neg_nan) == 1) r.update_nan (m_neg_nan); + else if (!m_pos_nan && !m_neg_nan) + r.clear_nan (); } bool diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 859c7fb4af9..852ac09f2c4 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -4051,6 +4051,15 @@ range_tests_floats () ASSERT_TRUE (real_isinf (&r0.lower_bound (), true)); ASSERT_TRUE (real_isinf (&r0.upper_bound (), true)); } + + // Test that reading back a global range yields the same result as + // what we wrote into it. + tree ssa = make_temp_ssa_name (float_type_node, NULL, "blah"); + r0.set_varying (float_type_node); + r0.clear_nan (); + set_range_info (ssa, r0); + get_global_range_query ()->range_of_expr (r1, ssa); + ASSERT_EQ (r0, r1); } // Run floating range tests for various combinations of NAN and INF -- 2.38.1