From patchwork Thu May 30 06:58:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1107579 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-501940-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Zz4k4Hrc"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45Dz2P3fY0z9s3l for ; Thu, 30 May 2019 16:58:53 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=lsRNlM81x5YQ7nL+7U8LNmfCmenCEmkHEfZXnuGNXb450qVHJOV59 RObqlKSoYiDFkHHvTw6WU7GFRi1E+I1q803PLZpCGrfaSRfuE7Edq0MKnRN9dWl8 Bhs77mrPBWSXhpF0Ss5xbyMN4/4dqkP561JL9zz71qRx1pvioDixyw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=2X5JpPt74eI/mwVquDF1axP447I=; b=Zz4k4Hrc/QmnFtz3pm3r qvbybyUumTBzdUYUqqJFTDszUTowIaadOe+X650b/AVyU/DqYmEtWnj0h4OtaSsE SW4F7DzdyWhfjrlKpBQBj/clt1angkk35E+Fi8V+TU4WZF8MRE/V5/FmwuGygNa9 3uiylRcEOG/wFyS1dyC99X8= Received: (qmail 62743 invoked by alias); 30 May 2019 06:58:46 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 62735 invoked by uid 89); 30 May 2019 06:58:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=business X-HELO: mail-wr1-f47.google.com Received: from mail-wr1-f47.google.com (HELO mail-wr1-f47.google.com) (209.85.221.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 30 May 2019 06:58:44 +0000 Received: by mail-wr1-f47.google.com with SMTP id l2so3354746wrb.9 for ; Wed, 29 May 2019 23:58:43 -0700 (PDT) Received: from abulafia.quesejoda.com (96.red-79-147-188.dynamicip.rima-tde.net. [79.147.188.96]) by smtp.gmail.com with ESMTPSA id 95sm3521306wrk.70.2019.05.29.23.58.40 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Wed, 29 May 2019 23:58:40 -0700 (PDT) From: Aldy Hernandez Subject: value_range_base::{non_zero_p, set_zero, set_non_zero} To: gcc-patches Message-ID: Date: Thu, 30 May 2019 02:58:39 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi. We have zero_p in the API, but we don't have non_zero_p. Instead we use a non-API function range_is_nonnull. I've fixed this. I have also gotten rid of the duplicity of using the non-API range_is_null in favor of value_range_base::zero_p(). Furthermore, there's value_range*::set_null and value_range*::set_nonnull(). It's inconsistent to use null/nonnull as well as zero/non_zero throughout. I've moved everything to *zero. Finally, it seems to me that the derived value_range versions of set_*zero/null are a bit confusing in that they clear equivalences behind the scenes. There's no intuitive reason why setting a range of [0,0] versus [5,10] should clear equivalences. I've made the equivalence nuking explicit in the handful of places where we do this, and thus reduced the need for separate value_range versions. I believe with these changes, as well as the pending intersect patch, we've cleaned up the remaining value_range uses where we actually wanted to use value_range_base. Or at least the remaining "value_range tem" business. OK? Aldy commit 55294d340a0727dbe985ee4bf3c1969a19bcbe6d Author: Aldy Hernandez Date: Tue May 28 19:30:31 2019 +0200 * tree-vrp.h (value_range_base::non_zero_p): New. (value_range_base::set_nonnull): Rename to... (value_range_base::set_non_zero): ...this. (value_range_base::set_null): Rename to... (value_range_base::set_zero): ...this. (value_range::set_nonnull): Remove. (value_range::set_null): Remove. * tree-vrp.c (range_is_null): Remove. (range_is_nonnull): Remove. (extract_range_from_binary_expr): Use value_range_base::*zero_p instead of range_is_*null. (extract_range_from_unary_expr): Same. (value_range_base::set_nonnull): Rename to... (value_range_base::set_non_zero): ...this. (value_range::set_nonnull): Remove. (value_range_base::set_null): Rename to... (value_range_base::set_zero): ...this. (value_range::set_null): Remove. (extract_range_from_binary_expr): Rename set_*null uses to set_*zero. (extract_range_from_unary_expr): Same. (union_helper): Same. * vr-values.c (get_value_range): Use set_*zero instead of set_*null. (vr_values::extract_range_from_binary_expr): Same. (vr_values::extract_range_basic): Same. diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 0a172719e5d..ef0ed97748b 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -776,32 +776,19 @@ value_range::set (tree val) set (VR_RANGE, val, val, NULL); } -/* Set value range VR to a non-NULL range of type TYPE. */ +/* Set value range VR to a non-zero range of type TYPE. */ void -value_range_base::set_nonnull (tree type) +value_range_base::set_non_zero (tree type) { tree zero = build_int_cst (type, 0); set (VR_ANTI_RANGE, zero, zero); } -void -value_range::set_nonnull (tree type) -{ - tree zero = build_int_cst (type, 0); - set (VR_ANTI_RANGE, zero, zero, NULL); -} - -/* Set value range VR to a NULL range of type TYPE. */ - -void -value_range_base::set_null (tree type) -{ - set (build_int_cst (type, 0)); -} +/* Set value range VR to a ZERO range of type TYPE. */ void -value_range::set_null (tree type) +value_range_base::set_zero (tree type) { set (build_int_cst (type, 0)); } @@ -830,22 +817,6 @@ vrp_bitmap_equal_p (const_bitmap b1, const_bitmap b2) && bitmap_equal_p (b1, b2))); } -/* Return true if VR is [0, 0]. */ - -static inline bool -range_is_null (const value_range_base *vr) -{ - return vr->zero_p (); -} - -static inline bool -range_is_nonnull (const value_range_base *vr) -{ - return (vr->kind () == VR_ANTI_RANGE - && vr->min () == vr->max () - && integer_zerop (vr->min ())); -} - /* Return true if max and min of VR are INTEGER_CST. It's not necessary a singleton. */ @@ -1583,9 +1554,9 @@ extract_range_from_binary_expr (value_range_base *vr, code is EXACT_DIV_EXPR. We could mask out bits in the resulting range, but then we also need to hack up vrp_union. It's just easier to special case when vr0 is ~[0,0] for EXACT_DIV_EXPR. */ - if (code == EXACT_DIV_EXPR && range_is_nonnull (&vr0)) + if (code == EXACT_DIV_EXPR && vr0.non_zero_p ()) { - vr->set_nonnull (expr_type); + vr->set_non_zero (expr_type); return; } @@ -1663,9 +1634,9 @@ extract_range_from_binary_expr (value_range_base *vr, If both are null, then the result is null. Otherwise they are varying. */ if (!range_includes_zero_p (&vr0) && !range_includes_zero_p (&vr1)) - vr->set_nonnull (expr_type); - else if (range_is_null (&vr0) && range_is_null (&vr1)) - vr->set_null (expr_type); + vr->set_non_zero (expr_type); + else if (vr0.zero_p () && vr1.zero_p ()) + vr->set_zero (expr_type); else vr->set_varying (); } @@ -1692,9 +1663,9 @@ extract_range_from_binary_expr (value_range_base *vr, && (flag_delete_null_pointer_checks || (range_int_cst_p (&vr1) && !tree_int_cst_sign_bit (vr1.max ())))) - vr->set_nonnull (expr_type); - else if (range_is_null (&vr0) && range_is_null (&vr1)) - vr->set_null (expr_type); + vr->set_non_zero (expr_type); + else if (vr0.zero_p () && vr1.zero_p ()) + vr->set_zero (expr_type); else vr->set_varying (); } @@ -1703,9 +1674,9 @@ extract_range_from_binary_expr (value_range_base *vr, /* For pointer types, we are really only interested in asserting whether the expression evaluates to non-NULL. */ if (!range_includes_zero_p (&vr0) && !range_includes_zero_p (&vr1)) - vr->set_nonnull (expr_type); - else if (range_is_null (&vr0) || range_is_null (&vr1)) - vr->set_null (expr_type); + vr->set_non_zero (expr_type); + else if (vr0.zero_p () || vr1.zero_p ()) + vr->set_zero (expr_type); else vr->set_varying (); } @@ -1898,7 +1869,7 @@ extract_range_from_binary_expr (value_range_base *vr, bool extra_range_p; /* Special case explicit division by zero as undefined. */ - if (range_is_null (&vr1)) + if (vr1.zero_p ()) { vr->set_undefined (); return; @@ -1937,7 +1908,7 @@ extract_range_from_binary_expr (value_range_base *vr, } else if (code == TRUNC_MOD_EXPR) { - if (range_is_null (&vr1)) + if (vr1.zero_p ()) { vr->set_undefined (); return; @@ -2141,9 +2112,9 @@ extract_range_from_unary_expr (value_range_base *vr, if (POINTER_TYPE_P (type) || POINTER_TYPE_P (op0_type)) { if (!range_includes_zero_p (&vr0)) - vr->set_nonnull (type); - else if (range_is_null (&vr0)) - vr->set_null (type); + vr->set_non_zero (type); + else if (vr0.zero_p ()) + vr->set_zero (type); else vr->set_varying (); return; @@ -6152,7 +6123,7 @@ value_range_base::union_helper (const value_range_base *vr0, vr1->kind (), vr1->min (), vr1->max ()); /* Work on a temporary so we can still use vr0 when union returns varying. */ - value_range tem; + value_range_base tem; tem.set_and_canonicalize (vr0type, vr0min, vr0max); /* Failed to find an efficient meet. Before giving up and setting @@ -6162,7 +6133,7 @@ value_range_base::union_helper (const value_range_base *vr0, && range_includes_zero_p (vr0) == 0 && range_includes_zero_p (vr1) == 0) { - tem.set_nonnull (vr0->type ()); + tem.set_non_zero (vr0->type ()); return tem; } diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h index 9d52b428d05..11ecf939ee2 100644 --- a/gcc/tree-vrp.h +++ b/gcc/tree-vrp.h @@ -46,8 +46,8 @@ public: void set (value_range_kind, tree, tree); void set (tree); - void set_nonnull (tree); - void set_null (tree); + void set_non_zero (tree); + void set_zero (tree); enum value_range_kind kind () const; tree min () const; @@ -72,6 +72,7 @@ public: bool may_contain_p (tree) const; void set_and_canonicalize (enum value_range_kind, tree, tree); bool zero_p () const; + bool non_zero_p () const; bool singleton_p (tree *result = NULL) const; void dump (FILE *) const; @@ -118,8 +119,6 @@ class GTY((user)) value_range : public value_range_base /* Deep-copies equiv bitmap argument. */ void set (value_range_kind, tree, tree, bitmap = NULL); void set (tree); - void set_nonnull (tree); - void set_null (tree); bool operator== (const value_range &) const /* = delete */; bool operator!= (const value_range &) const /* = delete */; @@ -222,6 +221,16 @@ value_range_base::zero_p () const && integer_zerop (m_max)); } +/* Return TRUE if range is non-zero. */ + +inline bool +value_range_base::non_zero_p () const +{ + return (m_kind == VR_ANTI_RANGE + && integer_zerop (m_min) + && integer_zerop (m_max)); +} + extern void dump_value_range (FILE *, const value_range *); extern void dump_value_range (FILE *, const value_range_base *); diff --git a/gcc/vr-values.c b/gcc/vr-values.c index 0e10aca92bb..fa91ee5aade 100644 --- a/gcc/vr-values.c +++ b/gcc/vr-values.c @@ -118,7 +118,10 @@ vr_values::get_value_range (const_tree var) if (POINTER_TYPE_P (TREE_TYPE (sym)) && (nonnull_arg_p (sym) || get_ptr_nonnull (var))) - vr->set_nonnull (TREE_TYPE (sym)); + { + vr->set_non_zero (TREE_TYPE (sym)); + vr->equiv_clear (); + } else if (INTEGRAL_TYPE_P (TREE_TYPE (sym))) { get_range_info (var, *vr); @@ -130,7 +133,10 @@ vr_values::get_value_range (const_tree var) } else if (TREE_CODE (sym) == RESULT_DECL && DECL_BY_REFERENCE (sym)) - vr->set_nonnull (TREE_TYPE (sym)); + { + vr->set_non_zero (TREE_TYPE (sym)); + vr->equiv_clear (); + } } return vr; @@ -858,7 +864,10 @@ vr_values::extract_range_from_binary_expr (value_range *vr, || (vr1.kind () == VR_ANTI_RANGE && vr1.min () == op0 && vr1.min () == vr1.max ()))) - vr->set_nonnull (expr_type); + { + vr->set_non_zero (expr_type); + vr->equiv_clear (); + } } /* Extract range information from a unary expression CODE OP0 based on @@ -1085,7 +1094,8 @@ vr_values::extract_range_basic (value_range *vr, gimple *stmt) && TREE_CODE (SSA_NAME_VAR (arg)) == PARM_DECL && cfun->after_inlining) { - vr->set_null (type); + vr->set_zero (type); + vr->equiv_clear (); return; } break; @@ -1392,7 +1402,10 @@ vr_values::extract_range_basic (value_range *vr, gimple *stmt) && gimple_stmt_nonnegative_warnv_p (stmt, &sop)) set_value_range_to_nonnegative (vr, type); else if (vrp_stmt_computes_nonzero (stmt)) - vr->set_nonnull (type); + { + vr->set_non_zero (type); + vr->equiv_clear (); + } else vr->set_varying (); }