From patchwork Thu Oct 6 06:23:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1754 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp166366wrs; Wed, 5 Oct 2022 23:24:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5uzh/aFCgVdivU78ev6S83Yka4imqq5wV6FuKGkTPk2N6E4fLoBg0qnfQ+PIGJbWilqW3h X-Received: by 2002:aa7:d95a:0:b0:458:896b:3cb9 with SMTP id l26-20020aa7d95a000000b00458896b3cb9mr3071769eds.253.1665037468749; Wed, 05 Oct 2022 23:24:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665037468; cv=none; d=google.com; s=arc-20160816; b=Wi7S9ZsjLK/7oYkWJpz6mk0C1sYjW0fW0UnWofxWqQYPd+zI33jWTO45Z05XMGyaOl yt2/B9o84GYVg2TNB9SroJiOrFhZ2wIySxtrRrEGEPtUrWb314+uomfRF1VDWFXvwCph baeyanZ0FSB7GgeVuwHnO1LJqpzXnY6I8KTQ8YbmHWTcu8OcaOVSyKG9oDxgmTHR/uiW K7H6cBcdnLf2TAQVYp4QCVt3EOhpVQ1rv1z92vwo1563wS9QnfUudilFsvnFA1YyeNnF RiMcb6XewXaEDTiD96n9MSfy56igZgoXx+hM4jNkG14QOepnODYDlBxeoPMGKvOtTkll 9G+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=GJKC/KZksv4ZYut4S09O79X0iVRHjLsMyF+sVC/MSbs=; b=pfXLzfv804/ltwSKF/q91OXyelZ3/LTbYVVTGryw1fLELfac4XDcWvmh+Xc4HbUF9E 62cr3KI31kIKu0VSr4+OwwePO6KV8CneBjrHzffQMqtJX1vm+haUGcrPSRln8rol6OBx 3EDE+AzePSC9/FoiRThbmfkGAU4gYQGxwOOBBgaqL/H2sDCNK9K/Nd//pVjeqRLY+oG3 zFJjtwOJiHKCgsIrCu8M5ZmEEbKfbOfDeDppZioobY9HdxFfIkfyy5BT6E6Nc1twdz3c V46FFbI26KIfi2ced3VaEy75V5QoPrJlN/R54S0/1jYWa/sakaiIOE03hXz3zQIXEIyD Ex8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Puwcw2dG; 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 p2-20020a170906614200b0078bbade136asi8399840ejl.923.2022.10.05.23.24.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 23:24:28 -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=Puwcw2dG; 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 651C6384D16E for ; Thu, 6 Oct 2022 06:24:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 651C6384D16E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665037449; bh=GJKC/KZksv4ZYut4S09O79X0iVRHjLsMyF+sVC/MSbs=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Puwcw2dGBp3gHo75cayoa5FSZOI861GQnIfedlfxQgMjccaQx5wQ7u0JjXyJrl+Pr CQcJaowiMhjNmGvSLtu4cjnbEUXF+sSA8gm9ZCGImOvHediQCy7eqlQJGMyrpWTFv1 oZDjgzE7aKZLJrCakanrCl11lj6Bi0+JRZ/egoi4= 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 0B0A5384D16B for ; Thu, 6 Oct 2022 06:23:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0B0A5384D16B Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-221-wKo5_bibPCSmIRQMGK75Jw-1; Thu, 06 Oct 2022 02:23:23 -0400 X-MC-Unique: wKo5_bibPCSmIRQMGK75Jw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 07A96101CC6B for ; Thu, 6 Oct 2022 06:23:23 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.138]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A41E8492B05; Thu, 6 Oct 2022 06:23:22 +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 2966NKoh1710022 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 6 Oct 2022 08:23:21 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 2966NKbR1710021; Thu, 6 Oct 2022 08:23:20 +0200 To: GCC patches Subject: [COMMITTED] Setting explicit NANs sets UNDEFINED for -ffinite-math-only. Date: Thu, 6 Oct 2022 08:23:18 +0200 Message-Id: <20221006062318.1709996-3-aldyh@redhat.com> In-Reply-To: <20221006062318.1709996-1-aldyh@redhat.com> References: <20221006062318.1709996-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.5 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 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 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?1745918329193797360?= X-GMAIL-MSGID: =?utf-8?q?1745918329193797360?= We recently agreed that setting a range of NAN should instead set UNDEFINED for -ffinite-math-only. This patch makes that change to frange::set_nan() directly. Also, calling frange::update_nan() will now be a nop for !HONOR_NANS. Doing this in the setters simplifies everywhere we set NANs, as it keeps us from introducing NANs by mistake. gcc/ChangeLog: * value-range.cc (frange::set): Call set_nan unconditionally. (range_tests_nan): Adjust tests. (range_tests_signed_zeros): Same. (range_tests_floats): Same. * value-range.h (frange::update_nan): Guard with HONOR_NANS. (frange::set_nan): Set undefined if !HONOR_NANS. --- gcc/value-range.cc | 59 ++++++++++++++++++++++----------------------- gcc/value-range.h | 60 +++++++++++++++++++++++++++++----------------- 2 files changed, 67 insertions(+), 52 deletions(-) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index a307559b654..87239fafa77 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -304,13 +304,8 @@ frange::set (tree type, if (real_isnan (&min) || real_isnan (&max)) { gcc_checking_assert (real_identical (&min, &max)); - if (HONOR_NANS (type)) - { - bool sign = real_isneg (&min); - set_nan (type, sign); - } - else - set_undefined (); + bool sign = real_isneg (&min); + set_nan (type, sign); return; } @@ -3624,6 +3619,7 @@ range_tests_nan () { frange r0, r1; REAL_VALUE_TYPE q, r; + bool signbit; // Equal ranges but with differing NAN bits are not equal. if (HONOR_NANS (float_type_node)) @@ -3735,6 +3731,26 @@ range_tests_nan () r0.set_nan (float_type_node); r0.clear_nan (); ASSERT_TRUE (r0.undefined_p ()); + + // [10,20] NAN ^ [21,25] NAN = [NAN] + r0 = frange_float ("10", "20"); + r0.update_nan (); + r1 = frange_float ("21", "25"); + r1.update_nan (); + r0.intersect (r1); + ASSERT_TRUE (r0.known_isnan ()); + + // NAN U [5,6] should be [5,6] +-NAN. + r0.set_nan (float_type_node); + r1 = frange_float ("5", "6"); + r1.clear_nan (); + 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.signbit_p (signbit)); + ASSERT_TRUE (r0.maybe_isnan ()); } static void @@ -3742,7 +3758,6 @@ 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; bool signbit; @@ -3788,18 +3803,6 @@ range_tests_signed_zeros () r0.intersect (r1); ASSERT_TRUE (r0.zero_p ()); - // NAN U [5,6] should be [5,6] NAN. - r0.set_nan (float_type_node); - r1 = frange_float ("5", "6"); - r1.clear_nan (); - 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.signbit_p (signbit)); - ASSERT_TRUE (r0.maybe_isnan ()); - r0 = frange_float ("+0", "5"); r0.clear_nan (); ASSERT_TRUE (r0.signbit_p (signbit) && !signbit); @@ -3823,7 +3826,10 @@ range_tests_signed_zeros () r1 = frange_float ("0", "0"); r1.update_nan (); r0.intersect (r1); - ASSERT_TRUE (r0.known_isnan ()); + if (HONOR_NANS (float_type_node)) + ASSERT_TRUE (r0.known_isnan ()); + else + ASSERT_TRUE (r0.undefined_p ()); r0.set_nonnegative (float_type_node); ASSERT_TRUE (r0.signbit_p (signbit) && !signbit); @@ -3863,7 +3869,8 @@ range_tests_floats () { frange r0, r1; - range_tests_nan (); + if (HONOR_NANS (float_type_node)) + range_tests_nan (); range_tests_signbit (); if (HONOR_SIGNED_ZEROS (float_type_node)) @@ -3936,14 +3943,6 @@ range_tests_floats () r0.intersect (r1); ASSERT_EQ (r0, frange_float ("15", "20")); - // [10,20] NAN ^ [21,25] NAN = [NAN] - r0 = frange_float ("10", "20"); - r0.update_nan (); - r1 = frange_float ("21", "25"); - r1.update_nan (); - r0.intersect (r1); - ASSERT_TRUE (r0.known_isnan ()); - // [10,20] ^ [21,25] = [] r0 = frange_float ("10", "20"); r0.clear_nan (); diff --git a/gcc/value-range.h b/gcc/value-range.h index d1663620444..b06ca7477cd 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -1111,11 +1111,14 @@ inline void frange::update_nan () { gcc_checking_assert (!undefined_p ()); - m_pos_nan = true; - m_neg_nan = true; - normalize_kind (); - if (flag_checking) - verify_range (); + if (HONOR_NANS (m_type)) + { + m_pos_nan = true; + m_neg_nan = true; + normalize_kind (); + if (flag_checking) + verify_range (); + } } // Like above, but set the sign of the NAN. @@ -1124,11 +1127,14 @@ inline void frange::update_nan (bool sign) { gcc_checking_assert (!undefined_p ()); - m_pos_nan = !sign; - m_neg_nan = sign; - normalize_kind (); - if (flag_checking) - verify_range (); + if (HONOR_NANS (m_type)) + { + m_pos_nan = !sign; + m_neg_nan = sign; + normalize_kind (); + if (flag_checking) + verify_range (); + } } // Clear the NAN bit and adjust the range. @@ -1213,12 +1219,17 @@ frange_val_is_max (const REAL_VALUE_TYPE &r, const_tree type) inline void frange::set_nan (tree type) { - m_kind = VR_NAN; - m_type = type; - m_pos_nan = true; - m_neg_nan = true; - if (flag_checking) - verify_range (); + if (HONOR_NANS (type)) + { + m_kind = VR_NAN; + m_type = type; + m_pos_nan = true; + m_neg_nan = true; + if (flag_checking) + verify_range (); + } + else + set_undefined (); } // Build a NAN of type TYPE with SIGN. @@ -1226,12 +1237,17 @@ frange::set_nan (tree type) inline void frange::set_nan (tree type, bool sign) { - m_kind = VR_NAN; - m_type = type; - m_neg_nan = sign; - m_pos_nan = !sign; - if (flag_checking) - verify_range (); + if (HONOR_NANS (type)) + { + m_kind = VR_NAN; + m_type = type; + m_neg_nan = sign; + m_pos_nan = !sign; + if (flag_checking) + verify_range (); + } + else + set_undefined (); } // Return TRUE if range is known to be finite.