From patchwork Tue Aug 30 12:25:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 836 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1815406wro; Tue, 30 Aug 2022 05:27:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR4hLZxA2QF8S0sgPXiNyqPMotjqk6O7tigUXRTGH+odi9iFvQXZYgh4/8VGXli4j9kKcSbZ X-Received: by 2002:a05:6402:2816:b0:434:ed38:16f3 with SMTP id h22-20020a056402281600b00434ed3816f3mr20187757ede.116.1661862421195; Tue, 30 Aug 2022 05:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661862421; cv=none; d=google.com; s=arc-20160816; b=tyPwxKhKKBZjN9iUlIqPA+GZpA6Q/c4wZE1R9WL3iwmRuB7xcNIUzgRkoznwDLa+AG NMPpIrvet5Nl2bzyC9MfLXbayktuEQrqgS69VbycXhKVGG15kMrl6W9HTZAh62cBEUnw RK3IX4VQATLE7xpBVOEC67xYw03ANLFNi1B+DXFkOljCNXHwqBvJS37i7xHU8HqIS1v1 dn2PBqMwqxijQtdfTN1eLoJ2mpCiFPbjDq2Sex3Y8+f5E6KLCFZvrX5rJ6w83lqGhQyp CZyomDkJ3GqAfJfYXzR717NOa/XpCj+hkIdzi05jWi9pxqM4/j/XRjRsRe5z0jW9OMdD 4RuA== 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:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=BbZJgd7Ul5WNNNsmtFU8v7n9CPFKkJsDYYBW+7QRfFY=; b=AMqNgq5MXLlA3V5/VOiUvQMRkFHCBQsIPmSXJFS565r7qhArFzlGWCAUSihSjxVkDZ Ar7P0f9kUehxBu0SiRF5Djgz47nnzl5oYZrOG+hy3JgErTKj7slqSp/u/BqkqJ1bGEaZ fDqenGrVTOyy+/Hmmh/BWAXa0g34vqWA8KBAyxLiIwePqiCPDBARhycX+msgJl4z88bT uXOxTnNQm7Pk3hpvHaeDel5O5sM34nfkhiP1oL72H3W4DAyJKx8hijCxJ7VoZNXqxRv9 VmWYavOcolr8xY94voWfUX7ZBEpWf2OPXOV7IO7ky1aEkSUwOwXVCy79jvqu8EGQs8Ny 6fug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JSg5Uzzi; 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 sg14-20020a170907a40e00b00730f3cb968fsi8090181ejc.990.2022.08.30.05.27.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 05:27:01 -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=JSg5Uzzi; 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 73130385356C for ; Tue, 30 Aug 2022 12:26:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 73130385356C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661862418; bh=BbZJgd7Ul5WNNNsmtFU8v7n9CPFKkJsDYYBW+7QRfFY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=JSg5UzziADMihzxQ8uV4Yg2yyZf7rFX6WspqAOv1UtTYPhGAy+MCl7ifrPv5kAL6R gl/FfKLwtgk6Ipd3PRXqr8ANY4Jnr/upxz5YwQFc6RgZ9C+z+1U0sf5xyvuJJkjqwd JceqLzJIlK7whe6Ae8iN1IMbfgPdnb0rYrlqQQfQ= 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 B73ED385C335 for ; Tue, 30 Aug 2022 12:26:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B73ED385C335 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-292-ZUwhXVrGPs-oeozzrvZmpw-1; Tue, 30 Aug 2022 08:26:09 -0400 X-MC-Unique: ZUwhXVrGPs-oeozzrvZmpw-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 2364C85A585 for ; Tue, 30 Aug 2022 12:26:09 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.104]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CFE1B492CA2; Tue, 30 Aug 2022 12:26:08 +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 27UCQ6ow1921089 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 30 Aug 2022 14:26:06 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 27UCQ5f71921088; Tue, 30 Aug 2022 14:26:05 +0200 To: GCC patches Subject: [COMMITTED] Force a [NAN, NAN] range when the definite NAN property is set. Date: Tue, 30 Aug 2022 14:25:53 +0200 Message-Id: <20220830122552.1921067-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.4 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 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?1742589049965729070?= X-GMAIL-MSGID: =?utf-8?q?1742589049965729070?= Setting the definite NAN property should also force a [NAN, NAN] range, otherwise we'd have two ways of representing a NAN: with the endpoints or with the property. In the ranger world we avoid at all costs having more than one representation for a range. In doing this, I removed the FRANGE_PROP_ACCESSOR macro, since it looks like setting a property may have repercurssions in the range itself, so it's best for the client to definte its own setter. gcc/ChangeLog: * value-range-storage.cc (frange_storage_slot::get_frange): Use frange_nan. * value-range.cc (frange::set_nan): New. (frange_nan): Move to header file. (range_tests_nan): Adjust frange_nan callers to pass type. New test. * value-range.h (FRANGE_PROP_ACCESSOR): Remove. (frange_nan): New. --- gcc/value-range-storage.cc | 4 +-- gcc/value-range.cc | 55 +++++++++++++++++++++++++------------- gcc/value-range.h | 26 +++++++++--------- 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc index adf23c39f0d..494392737ac 100644 --- a/gcc/value-range-storage.cc +++ b/gcc/value-range-storage.cc @@ -267,9 +267,7 @@ frange_storage_slot::get_frange (frange &r, tree type) const // endpoints. if (m_props.get_nan ().yes_p ()) { - REAL_VALUE_TYPE rv; - real_nan (&rv, "", 1, TYPE_MODE (type)); - r.set (type, rv, rv); + r = frange_nan (type); return; } diff --git a/gcc/value-range.cc b/gcc/value-range.cc index bcc6651701b..b6d6c62c06c 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -267,6 +267,29 @@ tree_compare (tree_code code, tree op1, tree op2) return !integer_zerop (fold_build2 (code, integer_type_node, op1, op2)); } +// Set the NAN property. Adjust the range if appopriate. + +void +frange::set_nan (fp_prop::kind k) +{ + if (k == fp_prop::YES) + { + gcc_checking_assert (!undefined_p ()); + *this = frange_nan (m_type); + return; + } + + // Setting NO on an obviously NAN range is nonsensical. + gcc_checking_assert (k != fp_prop::NO || !real_isnan (&m_min)); + + // Setting VARYING on an obviously NAN range is a no-op. + if (k == fp_prop::VARYING && real_isnan (&m_min)) + return; + + m_props.set_nan (k); + normalize_kind (); +} + // Setter for franges. void @@ -3493,17 +3516,6 @@ frange_float (const char *lb, const char *ub, tree type = float_type_node) return frange (type, min, max); } -// Build a NAN of type TYPE. - -static inline frange -frange_nan (tree type = float_type_node) -{ - REAL_VALUE_TYPE r; - - gcc_assert (real_nan (&r, "", 1, TYPE_MODE (type))); - return frange (type, r, r); -} - static void range_tests_nan () { @@ -3517,18 +3529,16 @@ range_tests_nan () ASSERT_NE (r0, r1); r0.set_nan (fp_prop::YES); ASSERT_NE (r0, r1); - r0.set_nan (fp_prop::VARYING); - ASSERT_EQ (r0, r1); // NAN ranges are not equal to each other. - r0 = frange_nan (); + r0 = frange_nan (float_type_node); r1 = r0; ASSERT_FALSE (r0 == r1); ASSERT_FALSE (r0 == r0); ASSERT_TRUE (r0 != r0); // Make sure that combining NAN and INF doesn't give any crazy results. - r0 = frange_nan (); + r0 = frange_nan (float_type_node); ASSERT_TRUE (r0.get_nan ().yes_p ()); r1 = frange_float ("+Inf", "+Inf"); r0.union_ (r1); @@ -3536,22 +3546,29 @@ range_tests_nan () ASSERT_TRUE (r0.varying_p ()); // [INF, INF] ^ NAN = VARYING - r0 = frange_nan (); + r0 = frange_nan (float_type_node); r1 = frange_float ("+Inf", "+Inf"); r0.intersect (r1); ASSERT_TRUE (r0.varying_p ()); // NAN ^ NAN = NAN - r0 = frange_nan (); - r1 = frange_nan (); + r0 = frange_nan (float_type_node); + r1 = frange_nan (float_type_node); r0.intersect (r1); ASSERT_TRUE (r0.get_nan ().yes_p ()); // VARYING ^ NAN = NAN. - r0 = frange_nan (); + r0 = frange_nan (float_type_node); r1.set_varying (float_type_node); r0.intersect (r1); ASSERT_TRUE (r0.get_nan ().yes_p ()); + + // Setting the NAN bit to yes, forces to range to [NAN, NAN]. + r0.set_varying (float_type_node); + r0.set_nan (fp_prop::YES); + ASSERT_TRUE (r0.get_nan ().yes_p ()); + ASSERT_TRUE (real_isnan (&r0.lower_bound ())); + ASSERT_TRUE (real_isnan (&r0.upper_bound ())); } static void diff --git a/gcc/value-range.h b/gcc/value-range.h index 43b231b8fe0..07379d58f88 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -323,16 +323,6 @@ private: } u; }; -// Accessors for getting/setting all FP properties at once. - -#define FRANGE_PROP_ACCESSOR(NAME) \ - fp_prop get_##NAME () const { return m_props.get_##NAME (); } \ - void set_##NAME (fp_prop::kind f) \ - { \ - m_props.set_##NAME (f); \ - normalize_kind (); \ - } - // A floating point range. class frange : public vrange @@ -371,8 +361,9 @@ public: const REAL_VALUE_TYPE &lower_bound () const; const REAL_VALUE_TYPE &upper_bound () const; - // Each fp_prop can be accessed with get_PROP() and set_PROP(). - FRANGE_PROP_ACCESSOR(nan) + // Accessors for FP properties. + fp_prop get_nan () const { return m_props.get_nan (); } + void set_nan (fp_prop::kind f); private: void verify_range (); bool normalize_kind (); @@ -1186,4 +1177,15 @@ real_min_representable (REAL_VALUE_TYPE *r, tree type) *r = real_value_negate (r); } +// Build a NAN of type TYPE. + +inline frange +frange_nan (tree type) +{ + REAL_VALUE_TYPE r; + + gcc_assert (real_nan (&r, "", 1, TYPE_MODE (type))); + return frange (type, r, r); +} + #endif // GCC_VALUE_RANGE_H