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 77B8E3858D32 for ; Sun, 4 Sep 2022 16:18:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 77B8E3858D32 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=1662308299; 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=EbZ/WzAGhK7Kzgrwd1K2rJnRbU7JJzRQ/HkzZKdg0iw=; b=YhxtFNNUAqsNNSXQe8HXtReslBN19bkuzppByqG5sytJ6MQB37T22Q1lejAyHA5bwC5QDe Tqq6UFs+KdIVipU5JvgE/5FSAWKSawUAMzR/y6m9gvwIGPVNXPZDewZfDOQMYg+8bCjol7 y++s0csAMWVXSdOBEf2BBTlZSoyxpuI= 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 From: Aldy Hernandez To: GCC patches Cc: Jakub Jelinek , Andrew MacLeod , Aldy Hernandez 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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 -- 2.37.1