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: 842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1876057wro; Tue, 30 Aug 2022 08:44:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR6GhVMH8X4ks9qsAsaMtBgQMmKEhlVvVZBdIg0ojx900YCzBi2ckvwuPVOTI0Hs1SeR9isb X-Received: by 2002:a17:906:c153:b0:741:78ac:853e with SMTP id dp19-20020a170906c15300b0074178ac853emr8380120ejc.191.1661874245147; Tue, 30 Aug 2022 08:44:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661874245; cv=none; d=google.com; s=arc-20160816; b=lPjjMorA2KA3kMfT/BYz8YB++FmKtKBdB/2Rwa408rPl1kIbjkxgYQrhRUrxK6ssHR KbX7RpePhPvkz2CG1WEf1lCkzsVu5WRaYt/WJJzxkgQW1HXjRvkTz/vriiOgqMbiFmu6 LzphiJLZ/+d3yuYrZa0fEhD0V1lpJCfoK8XKHxXPUf9gtu2/18bbAUztVWMO18GETJPL MGodZ3P5Buf+iuFrjT00Z68MHrRuDi+dZVfJtWb4MEvwGubFSUJkTr1b3KPQ1dfZwIq2 K7DYYwBwebiezh8knHSOdyhZGf1u2omo7gFn4s17orEJmfIdM+uUIT/OJ85x96t34GLX cIDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=8QHNrAGDaxnZ28Sy/W7xYYqdCxPp2UzurzMge7nOya0=; b=ZsNiYmIKinnZwAhA5euv1oMW23CVRR/u2RwXVqZplg0FYBKD7KwOW5rtdN6bjsWunL onrwrBVGj3qX1ZWhVlJVj2hxc6YsxeotY3pwz77Javo33O9q0nfnwAYXxpq0RyRubfa+ BGzTNNc/HvHDAQqtzXQjaOxg8YmwKjHiuiuiy6+vwdtTXJsC68SvUo8XUXptMxAebzlM Tc5Ft7zv/sPjrlFogt19LS49ckKwnEJIaqzuojOt4dx8gxSV4+KekBlLIbHbZga+Co3U rPqe2yUBkZxEgV76t8+mOVcmsok3U8Dl89OL0skDVrE2Cls82pct96iFOktswBb/3d2q iF1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="sglFcD/1"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qw21-20020a1709066a1500b0072b29827476si1675586ejc.287.2022.08.30.08.44.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 08:44:05 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="sglFcD/1"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 61B9A3AA943B for ; Tue, 30 Aug 2022 15:44:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61B9A3AA943B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661874241; 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=sglFcD/1rL0UeSpI3xOGh6wsayO8Q5PvJaRmBq06mxo50XJG5KbUUH4uzGufwJKXO M/pKixWNSDxNdIkMDiBCX0GMIjtuXV5sNEXziBOG7L3LSmf06fQqdTjLjH3jS7TZ1C z0O4/eqoymYpIpkFqNR+W6+i1IgMIpqvTZrkDQuw= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742601448457020084?= X-GMAIL-MSGID: =?utf-8?q?1742601448457020084?= 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);