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: 1673979 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=MfOXgd06; 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 4MLGzs6Y44z1yhk for ; Mon, 5 Sep 2022 02:18:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A03DE385AC3F for ; Sun, 4 Sep 2022 16:18:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A03DE385AC3F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662308320; 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=MfOXgd06eW0f47P1YfAB3QmxEbnCC6pKK3ioYQzSXr4oUBVwyOsyuoiDo6LtGc1Uf 9O/pZ7oizQxcoDAG/A6SJnDZyA4G0VIC7aZyo0xiqDoYKufvBD7kbzRaGYG2mKh8rn zZqqNCT6PuRbdulcdeMDK0TuJARUN1/UfpJBY0Y4= 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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