From patchwork Wed Nov 9 17:21:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1701865 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=Ju35oEfc; 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 4N6sHj73d0z1yqS for ; Thu, 10 Nov 2022 04:23:13 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 827813858C29 for ; Wed, 9 Nov 2022 17:23:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 827813858C29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668014591; bh=+J3M4NnfaqZCKT4thcxu4+LYdg5s4zk4AqI1uLuqP/8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Ju35oEfciXSILckLS2zp2R58VIhY2enxWmM7lu7CcW2Yqm/i/YeE81dhepfvWOhOc J6h4+1ONJYVkyhNNSxuyIGtZ7ArTewAXxqFYnxRzjMSmiiR+wVc9a5pt3biExlL6D4 Xbpvbi276EIJkA9BSRPv0dhXCpSxkNb4/hhv73NM= 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 7049E3858438 for ; Wed, 9 Nov 2022 17:22:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7049E3858438 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 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 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 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" 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