From patchwork Mon Nov 4 20:03:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1189140 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-512358-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="d+5tk+HA"; 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 476Nyt053rz9sP4 for ; Tue, 5 Nov 2019 07:03:33 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=KGwv/Bc9EZ1Vy/NT+4eM2iGa1FkX8LAAF9ZGvD5MSYomBWqDJn azCBT2Y7M2oUClZ10gQn9TfQ9IOxikTZNUtN8U/vc7hE1g3SO2LyG9bKHhBOTBwm 7QHb5yX+kXHxLG/1uPXP2vDIPNyZOvkghay47Zhq6A+FbPJz8Lh3uigi4= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=by7+Flq+iIouPskC0K2x+xCRAaI=; b=d+5tk+HAYuoO86q+GywZ rkokwzUdbxXn5KILCl5aY4LsKcTEhVE8xJh34V89k1pqMbVsVFnA0NvJWsdLdYla Y8D5mDMV4lPlED3+w0iAOjVPwdEVX+Dhdsk2+oAPssj7J1RB0+tmpLBxazk7tydY MHjuoYGPQkOi4/3l980XUns= Received: (qmail 42658 invoked by alias); 4 Nov 2019 20:03:26 -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 42650 invoked by uid 89); 4 Nov 2019 20:03:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=becoming, 7208, 6049, H*MI:b742 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 04 Nov 2019 20:03:24 +0000 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D9F892A09AD for ; Mon, 4 Nov 2019 20:03:22 +0000 (UTC) Received: by mail-wr1-f70.google.com with SMTP id e3so8443801wrs.17 for ; Mon, 04 Nov 2019 12:03:22 -0800 (PST) Received: from abulafia.quesejoda.com (149.red-81-32-135.dynamicip.rima-tde.net. [81.32.135.149]) by smtp.gmail.com with ESMTPSA id p12sm19978693wrm.62.2019.11.04.12.03.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Nov 2019 12:03:20 -0800 (PST) To: Andrew MacLeod , gcc-patches From: Aldy Hernandez Subject: always handle pointers in vrp_val*{min,max} Message-ID: Date: Mon, 4 Nov 2019 21:03:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 X-IsSubscribed: yes When I added the range-ops code, I had to teach vrp_val_is*{min,max} about pointers, since it would just ignore them and return NULL. I was overly cautious about changing existing behavior and decided to add a handle_pointers argument, with a default value of FALSE, and just changed the needed callers on a need-to basis. Little by little we've been changing every caller to TRUE, and it's becoming increasingly obvious that we should always handle pointers. I can't think of a reason why we wouldn't want to handle them, and if there is ever one, surely the caller can avoid calling these functions. OK for trunk? commit 4c4ce7228754d847daa3b99e4ee0d4c466512d1a Author: Aldy Hernandez Date: Mon Nov 4 17:55:57 2019 +0100 Remove handle_pointers argument from all the vrp_val*{min,max} functions. Always assume pointers should be handled. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c585360b537..a9870475ea7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,26 @@ +2019-11-04 Aldy Hernandez + + * tree-vrp.h (vrp_val_min): Remove handle_pointers argument. + (vrp_val_max): Same. + (vrp_val_is_min): Same. + (vrp_val_is_max): Same. + (value_range_base::nonzero_p): Remove last argument to + vrp_val_is_max. + * tree-vrp.c (vrp_val_min): Remove handle_pointers argument. + (vrp_val_max): Same. + (vrp_val_is_min): Same. + (vrp_val_is_max): Same. + (value_range_base::set_varying): Remove last argument to vrp_val*. + (value_range_base::dump): Same. + (value_range_base::set): Same. + (value_range_base::normalize_symbolics): Same. + (value_range_base::num_pairs): Same. + (value_range_base::lower_bound): Same. + (value_range_base::upper_bound): Same. + (ranges_from_anti_range): Remove handle_pointers argument. + (value_range_base::singleton_p): Remove last argument to + ranges_from_anti_range. + 2019-11-04 Aldy Hernandez * tree-vrp.c (range_int_cst_singleton_p): Remove. diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 070db903147..2d3e76af2a8 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -71,8 +71,7 @@ along with GCC; see the file COPYING3. If not see static bool ranges_from_anti_range (const value_range_base *ar, - value_range_base *vr0, value_range_base *vr1, - bool handle_pointers = false); + value_range_base *vr0, value_range_base *vr1); /* Set of SSA names found live during the RPO traversal of the function for still active basic-blocks. */ @@ -310,8 +309,8 @@ value_range_base::set_varying (tree type) m_kind = VR_VARYING; if (supports_type_p (type)) { - m_min = vrp_val_min (type, true); - m_max = vrp_val_max (type, true); + m_min = vrp_val_min (type); + m_max = vrp_val_max (type); } else /* We can't do anything range-wise with these types. */ @@ -382,7 +381,7 @@ value_range_base::singleton_p (tree *result) const if (num_pairs () == 1) { value_range_base vr0, vr1; - ranges_from_anti_range (this, &vr0, &vr1, true); + ranges_from_anti_range (this, &vr0, &vr1); return vr0.singleton_p (result); } } @@ -429,7 +428,7 @@ value_range_base::dump (FILE *file) const fprintf (file, ", "); if (supports_type_p (ttype) - && vrp_val_is_max (max (), true) + && vrp_val_is_max (max ()) && TYPE_PRECISION (ttype) != 1) fprintf (file, "+INF"); else @@ -574,11 +573,11 @@ static assert_locus **asserts_for; /* Return the maximum value for TYPE. */ tree -vrp_val_max (const_tree type, bool handle_pointers) +vrp_val_max (const_tree type) { if (INTEGRAL_TYPE_P (type)) return TYPE_MAX_VALUE (type); - if (POINTER_TYPE_P (type) && handle_pointers) + if (POINTER_TYPE_P (type)) { wide_int max = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type)); return wide_int_to_tree (const_cast (type), max); @@ -589,11 +588,11 @@ vrp_val_max (const_tree type, bool handle_pointers) /* Return the minimum value for TYPE. */ tree -vrp_val_min (const_tree type, bool handle_pointers) +vrp_val_min (const_tree type) { if (INTEGRAL_TYPE_P (type)) return TYPE_MIN_VALUE (type); - if (POINTER_TYPE_P (type) && handle_pointers) + if (POINTER_TYPE_P (type)) return build_zero_cst (const_cast (type)); return NULL_TREE; } @@ -604,9 +603,9 @@ vrp_val_min (const_tree type, bool handle_pointers) is not == to the integer constant with the same value in the type. */ bool -vrp_val_is_max (const_tree val, bool handle_pointers) +vrp_val_is_max (const_tree val) { - tree type_max = vrp_val_max (TREE_TYPE (val), handle_pointers); + tree type_max = vrp_val_max (TREE_TYPE (val)); return (val == type_max || (type_max != NULL_TREE && operand_equal_p (val, type_max, 0))); @@ -615,9 +614,9 @@ vrp_val_is_max (const_tree val, bool handle_pointers) /* Return whether VAL is equal to the minimum value of its type. */ bool -vrp_val_is_min (const_tree val, bool handle_pointers) +vrp_val_is_min (const_tree val) { - tree type_min = vrp_val_min (TREE_TYPE (val), handle_pointers); + tree type_min = vrp_val_min (TREE_TYPE (val)); return (val == type_min || (type_min != NULL_TREE && operand_equal_p (val, type_min, 0))); @@ -720,8 +719,8 @@ value_range_base::set (enum value_range_kind kind, tree min, tree max) tree typ = TREE_TYPE (min); if (supports_type_p (typ)) { - gcc_assert (vrp_val_min (typ, true)); - gcc_assert (vrp_val_max (typ, true)); + gcc_assert (vrp_val_min (typ)); + gcc_assert (vrp_val_max (typ)); } set_varying (typ); return; @@ -730,7 +729,7 @@ value_range_base::set (enum value_range_kind kind, tree min, tree max) /* Convert POLY_INT_CST bounds into worst-case INTEGER_CST bounds. */ if (POLY_INT_CST_P (min)) { - tree type_min = vrp_val_min (TREE_TYPE (min), true); + tree type_min = vrp_val_min (TREE_TYPE (min)); widest_int lb = constant_lower_bound_with_limit (wi::to_poly_widest (min), wi::to_widest (type_min)); @@ -738,7 +737,7 @@ value_range_base::set (enum value_range_kind kind, tree min, tree max) } if (POLY_INT_CST_P (max)) { - tree type_max = vrp_val_max (TREE_TYPE (max), true); + tree type_max = vrp_val_max (TREE_TYPE (max)); widest_int ub = constant_upper_bound_with_limit (wi::to_poly_widest (max), wi::to_widest (type_max)); @@ -824,7 +823,7 @@ value_range_base::set (enum value_range_kind kind, tree min, tree max) { tree one = build_int_cst (TREE_TYPE (max), 1); min = int_const_binop (PLUS_EXPR, max, one); - max = vrp_val_max (TREE_TYPE (max), true); + max = vrp_val_max (TREE_TYPE (max)); kind = VR_RANGE; } else if (is_max) @@ -1336,8 +1335,7 @@ vrp_set_zero_nonzero_bits (const tree expr_type, static bool ranges_from_anti_range (const value_range_base *ar, - value_range_base *vr0, value_range_base *vr1, - bool handle_pointers) + value_range_base *vr0, value_range_base *vr1) { tree type = ar->type (); @@ -1350,18 +1348,18 @@ ranges_from_anti_range (const value_range_base *ar, if (ar->kind () != VR_ANTI_RANGE || TREE_CODE (ar->min ()) != INTEGER_CST || TREE_CODE (ar->max ()) != INTEGER_CST - || !vrp_val_min (type, handle_pointers) - || !vrp_val_max (type, handle_pointers)) + || !vrp_val_min (type) + || !vrp_val_max (type)) return false; - if (tree_int_cst_lt (vrp_val_min (type, handle_pointers), ar->min ())) + if (tree_int_cst_lt (vrp_val_min (type), ar->min ())) vr0->set (VR_RANGE, - vrp_val_min (type, handle_pointers), + vrp_val_min (type), wide_int_to_tree (type, wi::to_wide (ar->min ()) - 1)); - if (tree_int_cst_lt (ar->max (), vrp_val_max (type, handle_pointers))) + if (tree_int_cst_lt (ar->max (), vrp_val_max (type))) vr1->set (VR_RANGE, wide_int_to_tree (type, wi::to_wide (ar->max ()) + 1), - vrp_val_max (type, handle_pointers)); + vrp_val_max (type)); if (vr0->undefined_p ()) { *vr0 = *vr1; @@ -6160,9 +6158,9 @@ value_range_base::normalize_symbolics () const { // [SYM, NUM] -> [-MIN, NUM] if (min_symbolic) - return value_range_base (VR_RANGE, vrp_val_min (ttype, true), max ()); + return value_range_base (VR_RANGE, vrp_val_min (ttype), max ()); // [NUM, SYM] -> [NUM, +MAX] - return value_range_base (VR_RANGE, min (), vrp_val_max (ttype, true)); + return value_range_base (VR_RANGE, min (), vrp_val_max (ttype)); } gcc_checking_assert (kind () == VR_ANTI_RANGE); // ~[SYM, NUM] -> [NUM + 1, +MAX] @@ -6171,7 +6169,7 @@ value_range_base::normalize_symbolics () const if (!vrp_val_is_max (max ())) { tree n = wide_int_to_tree (ttype, wi::to_wide (max ()) + 1); - return value_range_base (VR_RANGE, n, vrp_val_max (ttype, true)); + return value_range_base (VR_RANGE, n, vrp_val_max (ttype)); } value_range_base var; var.set_varying (ttype); @@ -6181,7 +6179,7 @@ value_range_base::normalize_symbolics () const if (!vrp_val_is_min (min ())) { tree n = wide_int_to_tree (ttype, wi::to_wide (min ()) - 1); - return value_range_base (VR_RANGE, vrp_val_min (ttype, true), n); + return value_range_base (VR_RANGE, vrp_val_min (ttype), n); } value_range_base var; var.set_varying (ttype); @@ -6203,7 +6201,7 @@ value_range_base::num_pairs () const { // ~[MIN, X] has one sub-range of [X+1, MAX], and // ~[X, MAX] has one sub-range of [MIN, X-1]. - if (vrp_val_is_min (m_min, true) || vrp_val_is_max (m_max, true)) + if (vrp_val_is_min (m_min) || vrp_val_is_max (m_max)) return 1; return 2; } @@ -6225,10 +6223,10 @@ value_range_base::lower_bound (unsigned pair) const if (m_kind == VR_ANTI_RANGE) { tree typ = type (); - if (pair == 1 || vrp_val_is_min (m_min, true)) + if (pair == 1 || vrp_val_is_min (m_min)) t = wide_int_to_tree (typ, wi::to_wide (m_max) + 1); else - t = vrp_val_min (typ, true); + t = vrp_val_min (typ); } else t = m_min; @@ -6250,8 +6248,8 @@ value_range_base::upper_bound (unsigned pair) const if (m_kind == VR_ANTI_RANGE) { tree typ = type (); - if (pair == 1 || vrp_val_is_min (m_min, true)) - t = vrp_val_max (typ, true); + if (pair == 1 || vrp_val_is_min (m_min)) + t = vrp_val_max (typ); else t = wide_int_to_tree (typ, wi::to_wide (m_min) - 1); } diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h index 1fde88fe0fe..5cd94733188 100644 --- a/gcc/tree-vrp.h +++ b/gcc/tree-vrp.h @@ -286,11 +286,11 @@ extern bool range_int_cst_p (const value_range_base *); extern int compare_values (tree, tree); extern int compare_values_warnv (tree, tree, bool *); extern int operand_less_p (tree, tree); -extern bool vrp_val_is_min (const_tree, bool handle_pointers = false); -extern bool vrp_val_is_max (const_tree, bool handle_pointers = false); +extern bool vrp_val_is_min (const_tree); +extern bool vrp_val_is_max (const_tree); -extern tree vrp_val_min (const_tree, bool handle_pointers = false); -extern tree vrp_val_max (const_tree, bool handle_pointers = false); +extern tree vrp_val_min (const_tree); +extern tree vrp_val_max (const_tree); void range_fold_unary_expr (value_range_base *, enum tree_code, tree type, const value_range_base *, tree op0_type); @@ -325,7 +325,7 @@ value_range_base::nonzero_p () const return (m_kind == VR_RANGE && TYPE_UNSIGNED (type ()) && integer_onep (m_min) - && vrp_val_is_max (m_max, true)); + && vrp_val_is_max (m_max)); } /* Return TRUE if *VR includes the value zero. */