From patchwork Wed Aug 5 14:17:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 140659 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 37DDD4BB24F0 for ; Wed, 5 Aug 2026 14:19:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37DDD4BB24F0 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=quesejoda.com header.i=@quesejoda.com header.a=rsa-sha256 header.s=dreamhost header.b=YjJunHMg X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from fuchsia.ash.relay.mailchannels.net (fuchsia.ash.relay.mailchannels.net [23.83.222.64]) by sourceware.org (Postfix) with ESMTPS id A7C504BA900C for ; Wed, 5 Aug 2026 14:18:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A7C504BA900C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=quesejoda.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quesejoda.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A7C504BA900C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=23.83.222.64 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785939505; cv=none; b=HdrSUJxs3AeZADKytAZz7QDoSImYxekDRNTUFENS2wHbgfniH6BFLWbZiW4gB2pviVN+J71vz3XxhOVxP7S6rdQj7lM8zSMMfBfp4iab4ZWRNOHFz57ZF9Z/QBq5HglQfkd3q/z+3fzici30vYaDeefp5HzMtGbbhY6yyYrAOMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785939505; c=relaxed/simple; bh=Yg5JbcxONyrm2uCwGk9qcXYBVtaD0fISJjgpMi0v7CE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=LRp2a62OkyPCocizjCunYlPbmbCV3s6n4bZCVCU72ZTKxCzGm/GkA+J++N6kWXRo0ULsuBpqCJai0q1tJCNXYJREOSbqsot79J2y0bmJNkVW8SmxfeqVBCMoCzysNkvLfEDLFCMThyiD3JRj7+gTwwHFqYWXow1z/nzReM5ZWaw= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=quesejoda.com header.i=@quesejoda.com header.a=rsa-sha256 header.s=dreamhost header.b=YjJunHMg DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7C504BA900C X-Sender-Id: dreamhost|x-authsender|aldy@quesejoda.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 7635D41C97; Wed, 05 Aug 2026 14:18:23 +0000 (UTC) Received: from pdx1-sub0-mail-a205.dreamhost.com (trex-green-8.trex.outbound.svc.cluster.local [100.111.248.111]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id EB20941566; Wed, 05 Aug 2026 14:18:18 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|aldy@quesejoda.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|aldy@quesejoda.com X-MailChannels-Auth-Id: dreamhost X-Unite-Lonely: 0b58af86088e8923_1785939503370_2685067518 X-MC-Loop-Signature: 1785939503370:818419319 X-MC-Ingress-Time: 1785939503370 Received: from pdx1-sub0-mail-a205.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.111.248.111 (trex/8.0.2); Wed, 05 Aug 2026 14:18:23 +0000 Received: from vesper.quesejoda.com (224.85-85-184.dynamic.clientes.euskaltel.es [85.85.184.224]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: aldy@quesejoda.com) by pdx1-sub0-mail-a205.dreamhost.com (Postfix) with ESMTPSA id 4hFXZJ1tW5z1gT; Wed, 5 Aug 2026 07:18:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quesejoda.com; s=dreamhost; t=1785939497; bh=EdNhxwIp10LKygVz/wqZwE7bpR3T7njogR3kWe23olA=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=YjJunHMg7nMeK2hqqVZjC2WIjxvPltC8/2YqtCcz8gxDq9pD9lZm2VJCt3nmn29hK yf2lyI3WXOjLaYugw60SrxCneUQATR2grgEddn16+u7DvKnD33GWzOFKwQ+524pjtZ TLpaarGgDlKx1puG25XcxzlRhsbtbMjV9NmXmoek5hfwze4YoVyUjWbYMoqNCO/sug 7WSyjgJNTrlppHIXerhwFR3D3P5dc1fX+5Dsy9Q2cZn4N/e1Qsa6jK/WMQARq+Ophw 8dU1a9xQBRyHsj4FPXmUwahVXExP1TY+v0jIz84FyHaHVQV77/kLrlvtBq8xzx9BuI VKcTNeLkR5dGg== From: Aldy Hernandez To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com, amacleod@redhat.com, rguenther@suse.de, Aldy Hernandez Subject: [PATCH 4/4] Remove nonzero_p. Date: Wed, 5 Aug 2026 16:17:25 +0200 Message-ID: <20260805141722.3769280-8-aldy@quesejoda.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260805141722.3769280-2-aldy@quesejoda.com> References: <20260805141722.3769280-2-aldy@quesejoda.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_HOSTKARMA_W, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org All callers now use contains_zero_p () or special case when appropriate. Tested on ppc64le Linux. gcc/ChangeLog: * value-range.h (vrange::nonzero_p): Remove. (unsupported_range::nonzero_p): Remove. (irange::nonzero_p): Remove. (prange::nonzero_p): Remove. (frange::nonzero_p): Remove. (Value_Range::nonzero_p): Remove. * value-range.cc (unsupported_range::nonzero_p): Remove. (frange::nonzero_p): Remove. (range_tests_misc): Test contains_zero_p instead of nonzero_p. (range_tests_sub_ranges_zero): Likewise. * range-op.cc (range_op_bitwise_and_tests): Likewise. --- gcc/range-op.cc | 2 +- gcc/value-range.cc | 50 +++++++++------------------------------------- gcc/value-range.h | 22 -------------------- 3 files changed, 10 insertions(+), 64 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index a1a479a8319..0bfc3fa3358 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -5297,7 +5297,7 @@ range_op_bitwise_and_tests () i1.set_nonzero (integer_type_node); i2.set_varying (integer_type_node); op_bitwise_or.fold_range (res, integer_type_node, i1, i2); - ASSERT_TRUE (res.nonzero_p ()); + ASSERT_FALSE (res.contains_zero_p ()); // (NEGATIVE | X) is nonzero. i1 = int_range<1> (integer_type_node, INT (-5), INT (-3)); diff --git a/gcc/value-range.cc b/gcc/value-range.cc index d45c3649582..3da1609f830 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -291,12 +291,6 @@ unsupported_range::zero_p () const return false; } -bool -unsupported_range::nonzero_p () const -{ - return false; -} - bool unsupported_range::contains_zero_p () const { @@ -1697,31 +1691,6 @@ frange::set_nonzero (tree type) set (type, dconstm0, dconst0, VR_ANTI_RANGE); } -// Return TRUE when this range is exactly the "everything but zero" set that -// set_nonzero builds, mirroring irange::nonzero_p. Callers wanting "does not -// contain zero" should use the !contains_p (0) idiom. -// -// A NAN is not a zero, so nonzero-ness depends only on the intervals, not on -// whether the range may also be a NAN. We therefore recognize the nonzero -// range by comparing intervals against set_nonzero's with the NAN state -// ignored. A strict *this == set_nonzero () would be wrong: set_nonzero -// leaves the NAN able to be either sign, so a range that is otherwise exactly -// nonzero but whose NAN has been cleared would compare unequal. - -bool -frange::nonzero_p () const -{ - if (undefined_p () || known_isnan ()) - return false; - - frange nz; - nz.set_nonzero (type ()); - nz.clear_nan (); - frange tmp = *this; - tmp.clear_nan (); - return tmp == nz; -} - // Return TRUE if the range contains zero (+0.0 or -0.0). bool @@ -3600,10 +3569,10 @@ range_tests_misc () r0 = range_int (0, 0); ASSERT_TRUE (r0.zero_p ()); - // Test nonzero_p(). + // Test contains_zero_p(). r0 = range_int (0, 0); r0.invert (); - ASSERT_TRUE (r0.nonzero_p ()); + ASSERT_FALSE (r0.contains_zero_p ()); // r0 = ~[1,1] r0 = range_int (1, 1, VR_ANTI_RANGE); @@ -3861,26 +3830,25 @@ range_tests_sub_ranges_zero () // Excluding zero from [-0.0, 5.0] eats the lower end entirely. r0.set_nonzero (float_type_node); - ASSERT_TRUE (r0.nonzero_p ()); + ASSERT_FALSE (r0.contains_zero_p ()); ASSERT_FALSE (r0.contains_p (dconst0)); ASSERT_FALSE (r0.contains_p (dconstm0)); - // A NAN is not a zero, so clearing the NAN leaves a nonzero range nonzero. + // A NAN is not a zero, so clearing the NAN leaves the range nonzero. r0.clear_nan (); - ASSERT_TRUE (r0.nonzero_p ()); + ASSERT_FALSE (r0.contains_zero_p ()); - // A range that merely avoids zero is not the nonzero range. + // A range that avoids zero does not contain zero. r0 = frange_float ("1.0", "10.0"); - ASSERT_FALSE (r0.nonzero_p ()); + ASSERT_FALSE (r0.contains_zero_p ()); - // Excluding zero from [-0.0, 5.0] leaves (0, 5]: it avoids zero but is not - // the whole nonzero range. + // Excluding zero from [-0.0, 5.0] leaves (0, 5], which does not contain zero. r0 = frange_float ("-0.0", "5.0"); r0.clear_nan (); r1 = frange_float_excluding ("0.0"); r0.intersect (r1); ASSERT_EQ (r0.num_pairs (), 1); - ASSERT_FALSE (r0.nonzero_p ()); + ASSERT_FALSE (r0.contains_zero_p ()); ASSERT_FALSE (r0.contains_p (dconst0)); ASSERT_FALSE (r0.contains_p (dconstm0)); ASSERT_TRUE (r0.contains_p (real_from_str ("5.0"))); diff --git a/gcc/value-range.h b/gcc/value-range.h index 260f822c8ea..0949c291697 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -102,7 +102,6 @@ public: virtual bool singleton_p (tree *result = NULL) const = 0; virtual bool contains_p (tree cst) const = 0; virtual bool zero_p () const = 0; - virtual bool nonzero_p () const = 0; virtual bool contains_zero_p () const = 0; virtual void set_nonzero (tree type) = 0; virtual void set_zero (tree type) = 0; @@ -315,7 +314,6 @@ public: // Predicates. virtual bool zero_p () const override; - virtual bool nonzero_p () const override; virtual bool contains_zero_p () const override; virtual bool singleton_p (tree *result = NULL) const override; bool singleton_p (wide_int &) const; @@ -423,7 +421,6 @@ public: virtual bool fits_p (const vrange &v) const final override; virtual bool singleton_p (tree *result = NULL) const final override; virtual bool zero_p () const final override; - virtual bool nonzero_p () const final override; virtual bool contains_zero_p () const final override; virtual void set (tree, tree, value_range_kind = VR_RANGE) final override; virtual tree type () const final override; @@ -524,7 +521,6 @@ public: bool singleton_p (tree * = NULL) const final override; bool contains_p (tree) const final override; bool zero_p () const final override; - bool nonzero_p () const final override; bool contains_zero_p () const final override; void set_nonzero (tree type) final override; void set_zero (tree type) final override; @@ -637,7 +633,6 @@ public: virtual bool supports_type_p (const_tree type) const override; virtual void accept (const vrange_visitor &v) const override; virtual bool zero_p () const override; - virtual bool nonzero_p () const override; virtual bool contains_zero_p () const override; virtual void set_nonzero (tree type) override; virtual void set_zero (tree type) override; @@ -890,7 +885,6 @@ public: void set_zero (tree type) { init (type); return m_vrange->set_zero (type); } void set_nonzero (tree type) { init (type); return m_vrange->set_nonzero (type); } - bool nonzero_p () const { return m_vrange->nonzero_p (); } bool contains_zero_p () const { return m_vrange->contains_zero_p (); } bool zero_p () const { return m_vrange->zero_p (); } tree lbound () const { return m_vrange->lbound (); } @@ -1133,16 +1127,6 @@ irange::zero_p () const && upper_bound (0) == 0); } -inline bool -irange::nonzero_p () const -{ - if (undefined_p ()) - return false; - - wide_int zero = wi::zero (TYPE_PRECISION (type ())); - return *this == int_range<2> (type (), zero, zero, VR_ANTI_RANGE); -} - inline bool irange::contains_zero_p () const { @@ -1480,12 +1464,6 @@ prange::zero_p () const return ret; } -inline bool -prange::nonzero_p () const -{ - return m_kind == VR_RANGE && m_min == 1 && m_max == -1; -} - inline bool prange::contains_zero_p () const {