From patchwork Sun Sep 4 16:18:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 953 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1607137wro; Sun, 4 Sep 2022 09:19:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR6IMjXh8JM/Iba9DhQ0tELf5YVe4tcUwHjeCKXx1M51ryF2L/hYxbsmqRa05D83Qg64iR3U X-Received: by 2002:a05:6402:2d6:b0:447:ae9d:d0f1 with SMTP id b22-20020a05640202d600b00447ae9dd0f1mr40632828edx.256.1662308344671; Sun, 04 Sep 2022 09:19:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662308344; cv=none; d=google.com; s=arc-20160816; b=i+BVIj7X2kcZMGPB/s+proEp1A60iuY6aGFHe5loesEJdzjpVY0jrroTmzbaszhjjF YXIPnho8IGr6CHBtfYx/VBezPD9U/rSQeGY+/o1MP/S7ziJNKqZj0I99PtV+AO601i05 R+rcQ9l577DisKsJceIbVl+/fKLBV4GZ9nZsgGyqsOwZY/jxLhND1LxnhCpqzwbMx4qS lf21jc+082+95GxEDzYbtRC46UxIhdPhOFB/uSbn2D9so/w6MQW6zmfBVU6B8VoKfOav 3FgUoocqzodWtMoki5SvXcURbCOivSBFdn/EV8ICplEWX8cdmX9biN9hhGQviFidmIxB iofw== 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=EbZ/WzAGhK7Kzgrwd1K2rJnRbU7JJzRQ/HkzZKdg0iw=; b=E06/3tsEz8m51+hcD5yPL2bTjeuLbimGmCikbzqMPpfKW+z20BJ9/36Ki9cvahVJ5H e41zBRFLNRaItlbtnhXvkGHpUyXpOgPAYmWuNagIZzjJ0PH89GalM/6rhdieIfzkcK8H NDGMedEA2Kjbo1Oz8zxCV6N7MNiIawcmPfAYtUX6glcHb2BLAMV1HFhIwwmDNK7yQsu7 QnxpGfhuPjUkqpIIReyWhl1231ilEoBIDDiIDxyud21TAbGiB7FD3NnKna0+1hIcBxZF bCj+XG8mdLGAukfR8L6a/EShGU7/vzccDaWAvdgVpu25emkz1RzeJOseag6CVDTvunjN YtqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Q2Q3a15A; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id ge13-20020a170907908d00b0073d6ed6ff15si4876070ejb.501.2022.09.04.09.19.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Sep 2022 09:19:04 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Q2Q3a15A; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 92EE33856DCD for ; Sun, 4 Sep 2022 16:19:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92EE33856DCD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662308343; bh=EbZ/WzAGhK7Kzgrwd1K2rJnRbU7JJzRQ/HkzZKdg0iw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Q2Q3a15AbSy99U24sf8I+n9G5tMxQAgPCnU64Za40xPpE4YN4HlYAJL+OJvanyNzz eyESZQDRqbAjRaF8cQ62RfPzOOyKWC28phRsHJBhgA/fdUkb+9yQeksi/LEbw5RV2x CHT+ArozWrbNEMvkyXl1zjJIcALKCOaUjMrCBTGg= 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 77B8E3858D32 for ; Sun, 4 Sep 2022 16:18:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 77B8E3858D32 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-203-BRKk40VKMta8ZrCML0DoXw-1; Sun, 04 Sep 2022 12:18:17 -0400 X-MC-Unique: BRKk40VKMta8ZrCML0DoXw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3FA9138060EC for ; Sun, 4 Sep 2022 16:18:17 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D0B9B40CF8E7; Sun, 4 Sep 2022 16:18:16 +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 284GIEEp3098057 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 4 Sep 2022 18:18:14 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 284GIEdc3098056; Sun, 4 Sep 2022 18:18:14 +0200 To: GCC patches Subject: [COMMITTED] Do not clobber signbit when unioning a NAN. Date: Sun, 4 Sep 2022 18:18:11 +0200 Message-Id: <20220904161811.3097999-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 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 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?1743056634841473218?= X-GMAIL-MSGID: =?utf-8?q?1743056634841473218?= When unioning a known NAN and something else, we're dropping the properties of the NAN, particularly the sign. This fixes the oversight. With this patch, we should be keeping the sign bit up to date, even in the presence of NANs. gcc/ChangeLog: * value-range.cc (frange::union_): Do not drop properties when unioning a NAN with something else. (range_tests_signed_zeros): Add tests. --- gcc/value-range.cc | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index a1c29f7bd0b..c9f42fe272c 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -475,19 +475,25 @@ frange::union_ (const vrange &v) return true; } - // If one side has a NAN, the union is just the other side plus the - // NAN bit. + // If one side has a NAN, the union is the other side, plus the union + // of the properties and the possibility of a NAN. if (get_nan ().yes_p ()) { + frange_props save = m_props; *this = r; - // NOP if NAN already set. + m_props = save; + m_props.union_ (r.m_props); set_nan (fp_prop::VARYING); + if (flag_checking) + verify_range (); return true; } if (r.get_nan ().yes_p ()) { - // NOP if NAN already set. + m_props.union_ (r.m_props); set_nan (fp_prop::VARYING); + if (flag_checking) + verify_range (); return true; } @@ -3676,6 +3682,7 @@ range_tests_signed_zeros () { tree zero = build_zero_cst (float_type_node); tree neg_zero = fold_build1 (NEGATE_EXPR, float_type_node, zero); + REAL_VALUE_TYPE q, r; frange r0, r1; // Since -0.0 == +0.0, a range of [-0.0, -0.0] should contain +0.0 @@ -3711,6 +3718,16 @@ range_tests_signed_zeros () r1.set_signbit (fp_prop::YES); r0.union_ (r1); ASSERT_TRUE (r0.zero_p () && r0.get_signbit ().varying_p ()); + + // NAN U [5,6] should be [5,6] with no sign info. + r0 = frange_nan (float_type_node); + r1 = frange_float ("5", "6"); + 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_signbit ().varying_p ()); } static void