From patchwork Tue Aug 30 15:43:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 57181 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 BEA2A3AA9825 for ; Tue, 30 Aug 2022 15:43:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEA2A3AA9825 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661874226; bh=8QHNrAGDaxnZ28Sy/W7xYYqdCxPp2UzurzMge7nOya0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=tt7x8EOCngnZgE25jG6yb1Q82ivPG8g2K2aZfN2xGPPBRnm9IMZGWgtnW/LKuQXK9 XSNdLcMrrPZpBkquW+M5zPfHrD/2Vo9cVzzVFP1igdyJN2FbnV0+Uit7ra6+z4lPtF m2Vl1Uf3II+IfJPi/wOoQAV7HuuteV0JPsBdqS1w= 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 4502E3851AAD for ; Tue, 30 Aug 2022 15:43:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4502E3851AAD 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-594-qehP9yaTPS2ew4nSsgE9_w-1; Tue, 30 Aug 2022 11:43:07 -0400 X-MC-Unique: qehP9yaTPS2ew4nSsgE9_w-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6E99B2999B45 for ; Tue, 30 Aug 2022 15:43:07 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 05DEF492CA2; Tue, 30 Aug 2022 15:43:06 +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 27UFh4d01965213 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 30 Aug 2022 17:43:04 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 27UFh4HG1965208; Tue, 30 Aug 2022 17:43:04 +0200 To: GCC patches Subject: [COMMITTED] Improve union of ranges containing NAN. Date: Tue, 30 Aug 2022 17:43:01 +0200 Message-Id: <20220830154301.1965174-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 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, 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 Cc: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Previously [5,6] U NAN would just drop to VARYING. With this patch, the resulting range becomes [5,6] with the NAN bit set to unknown. [I still have yet to decide what to do with intersections. ISTM, the intersection of a known NAN with anything else should be a NAN, but it could also be undefined (the empty set). I'll have to run some tests and see. Currently, we drop to VARYING cause well... it's always safe to give up;-).] gcc/ChangeLog: * value-range.cc (early_nan_resolve): Change comment. (frange::union_): Handle union when one side is a NAN. (range_tests_nan): Add tests for NAN union. --- gcc/value-range.cc | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index b6d6c62c06c..473139c6dbd 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -403,7 +403,7 @@ early_nan_resolve (frange &r, const frange &other) // There's nothing to do for both NANs. if (r.get_nan ().yes_p () == other.get_nan ().yes_p ()) return false; - // But only one NAN complicates things. + // ?? Perhaps the intersection of a NAN and anything is a NAN ??. r.set_varying (r.type ()); return true; } @@ -420,10 +420,22 @@ frange::union_ (const vrange &v) *this = r; return true; } - // ?? We could do better here. [5,6] U NAN should be [5,6] with the - // NAN maybe bits set. For now, this is conservatively correct. - if (get_nan ().yes_p () || r.get_nan ().yes_p ()) - return early_nan_resolve (*this, r); + + // If one side has a NAN, the union is just the other side plus the + // NAN bit. + if (get_nan ().yes_p ()) + { + *this = r; + // NOP if NAN already set. + set_nan (fp_prop::VARYING); + return true; + } + if (r.get_nan ().yes_p ()) + { + // NOP if NAN already set. + set_nan (fp_prop::VARYING); + return true; + } bool changed = m_props.union_ (r.m_props); @@ -3520,6 +3532,7 @@ static void range_tests_nan () { frange r0, r1; + REAL_VALUE_TYPE q, r; // Equal ranges but with differing NAN bits are not equal. r1 = frange_float ("10", "12"); @@ -3537,13 +3550,24 @@ range_tests_nan () ASSERT_FALSE (r0 == r0); ASSERT_TRUE (r0 != r0); - // Make sure that combining NAN and INF doesn't give any crazy results. + // [5,6] U NAN is [5,6] with an unknown NAN bit. + r0 = frange_float ("5", "6"); + r0.set_nan (fp_prop::NO); + r1 = frange_nan (float_type_node); + r0.union_ (r1); + real_from_string (&q, "5"); + real_from_string (&r, "6"); + ASSERT_TRUE (real_identical (&q, &r0.lower_bound ())); + ASSERT_TRUE (real_identical (&r, &r0.upper_bound ())); + ASSERT_TRUE (r0.get_nan ().varying_p ()); + + // NAN U NAN = NAN r0 = frange_nan (float_type_node); - ASSERT_TRUE (r0.get_nan ().yes_p ()); - r1 = frange_float ("+Inf", "+Inf"); + r1 = frange_nan (float_type_node); r0.union_ (r1); - // [INF, INF] U NAN = VARYING - ASSERT_TRUE (r0.varying_p ()); + ASSERT_TRUE (real_isnan (&r0.lower_bound ())); + ASSERT_TRUE (real_isnan (&r1.upper_bound ())); + ASSERT_TRUE (r0.get_nan ().yes_p ()); // [INF, INF] ^ NAN = VARYING r0 = frange_nan (float_type_node);