From patchwork Tue Jun 11 10:40:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1113651 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-502745-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="QbTMa+ta"; 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 45NRNs3R02z9s5c for ; Tue, 11 Jun 2019 20:40:39 +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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=DoPCzPoRgvVRbfeiDThvL+xsCfgeItEqJcoGZJAGbInBH8gA21 J+0Y5vLDWbPT/mTO4rzap6oEOe/YcxCdsoTWMZMfl8bpDk4TWFHVWKMjKnxeHCCM qy33Mq/hZOdoELA52GaqD8vwOPW8lyyscxgNrzCsteXEKsRAgHWGJ7mz4= 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=PFhrb7aRDuZVXk7TBXciCwURHIo=; b=QbTMa+talj9JvKl07beA I8MVRTgb18KITtEZvid+dwXrU3swP1CkG+oUhsFcP0r+06tZWgLf6xnzuIs1Ytl6 1rfhRZWHS+D3czD0rnendx6tMKjrx7eSpnWJfCKkuYhVJioS1Kb2tVDrpuq8XDNh Ffe21aEOycwON5QwZFg+N0I= Received: (qmail 15539 invoked by alias); 11 Jun 2019 10:40:32 -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 15520 invoked by uid 89); 11 Jun 2019 10:40:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=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= X-HELO: mail-qk1-f173.google.com Received: from mail-qk1-f173.google.com (HELO mail-qk1-f173.google.com) (209.85.222.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Jun 2019 10:40:30 +0000 Received: by mail-qk1-f173.google.com with SMTP id m14so7278066qka.10 for ; Tue, 11 Jun 2019 03:40:30 -0700 (PDT) Received: from abulafia.quesejoda.com ([148.101.34.1]) by smtp.gmail.com with ESMTPSA id q3sm5772316qkm.67.2019.06.11.03.40.27 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Tue, 11 Jun 2019 03:40:28 -0700 (PDT) To: gcc-patches From: Aldy Hernandez Subject: Add value_range_base::contains_p Message-ID: <6cbe0075-0250-ae99-7a2b-2198cecd40c4@redhat.com> Date: Tue, 11 Jun 2019 06:40:26 -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 This patch cleans up the various contains, may_contain, and value_inside_range variants we have throughout, in favor of one-- contains_p. There should be no changes in functionality. I have added a note to range_includes_zero_p, perhaps as a personal question than anything else. This function was/is returning true for UNDEFINED. From a semantic sense, that doesn't make sense. UNDEFINED is really the empty set. Is the functionality wrong, or should we call this function something else? Either way, I'm fine removing the comment but I'm genuinely curious. OK? commit eac5cbfa507146166498e395d9347efdf46d3ef4 Author: Aldy Hernandez Date: Tue Jun 4 09:11:22 2019 +0200 value_range_base::contains_p and may_contains_p. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bee0a75a000..4f5c1798751 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,17 @@ +2019-06-11 Aldy Hernandez + + * gimple-loop-versioning.cc (prune_loop_conditions): Use + value_range_base::contains_p. + * tree-vrp.c (value_range_base::may_contain_p): Remove. + (value_inside_range): Make private to value_range_base class. + (value_range_base::contains_p): New. + * tree-vrp.h (value_range_base): Remove may_contain_p. Add + contains_p. Add value_inside_range. + (range_includes_p): Remove. + (value_inside_range): Remove. + (range_includes_p): Use value_range_base::contains_p. + * vr-values.c (compare_range_with_value): Same. + 2019-06-11 Aldy Hernandez * gimple-ssa-evrp.c (evrp_dom_walker::before_dom_children): Use diff --git a/gcc/gimple-loop-versioning.cc b/gcc/gimple-loop-versioning.cc index a2f68bf08db..85468fa06c4 100644 --- a/gcc/gimple-loop-versioning.cc +++ b/gcc/gimple-loop-versioning.cc @@ -1489,7 +1489,8 @@ loop_versioning::prune_loop_conditions (struct loop *loop, vr_values *vrs) { tree name = ssa_name (i); value_range *vr = vrs->get_value_range (name); - if (vr && !range_includes_p (vr, 1)) + if (vr && (!vr->contains_p (build_one_cst (TREE_TYPE (name))) + && !vr->undefined_p ())) { if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, find_loop_location (loop), diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 08e6c6b6111..58ca9fa0d34 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -292,25 +292,6 @@ value_range::set_varying (tree type) equiv_clear (); } -/* Return TRUE if it is possible that range contains VAL. */ - -bool -value_range_base::may_contain_p (tree val) const -{ - if (varying_p ()) - return true; - - if (undefined_p ()) - return true; - - if (m_kind == VR_ANTI_RANGE) - { - int res = value_inside_range (val, min (), max ()); - return res == 0 || res == -2; - } - return value_inside_range (val, min (), max ()) != 0; -} - void value_range::equiv_clear () { @@ -1160,7 +1141,7 @@ compare_values (tree val1, tree val2) function. */ int -value_inside_range (tree val, tree min, tree max) +value_range_base::value_inside_range (tree val, tree min, tree max) const { int cmp1, cmp2; @@ -1177,15 +1158,23 @@ value_inside_range (tree val, tree min, tree max) return !cmp2; } - -/* Return TRUE if *VR includes the value X. */ +/* Return TRUE if range contains VAL. */ bool -range_includes_p (const value_range_base *vr, HOST_WIDE_INT x) +value_range_base::contains_p (tree val) const { - if (vr->varying_p () || vr->undefined_p ()) + if (varying_p ()) return true; - return vr->may_contain_p (build_int_cst (vr->type (), x)); + + if (undefined_p ()) + return false; + + if (m_kind == VR_ANTI_RANGE) + { + int res = value_inside_range (val, min (), max ()); + return res == 0 || res == -2; + } + return value_inside_range (val, min (), max ()) != 0; } /* Value range wrapper for wide_int_range_set_zero_nonzero_bits. diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h index e48cc37bafc..3abe0f7fe98 100644 --- a/gcc/tree-vrp.h +++ b/gcc/tree-vrp.h @@ -70,7 +70,7 @@ public: /* Misc methods. */ tree type () const; - bool may_contain_p (tree) const; + bool contains_p (tree) const; void set_and_canonicalize (enum value_range_kind, tree, tree); bool zero_p () const; bool nonzero_p () const; @@ -97,6 +97,9 @@ protected: friend void gt_ggc_mx (value_range_base *&); friend void gt_pch_nx (value_range_base &); friend void gt_pch_nx (value_range_base *, gt_pointer_operator, void *); + +private: + int value_inside_range (tree, tree, tree) const; }; /* Note value_range cannot currently be used with GC memory, only @@ -254,7 +257,6 @@ struct assert_info extern void register_edge_assert_for (tree, edge, enum tree_code, tree, tree, vec &); extern bool stmt_interesting_for_vrp (gimple *); -extern bool range_includes_p (const value_range_base *, HOST_WIDE_INT); extern bool infer_value_range (gimple *, tree, tree_code *, tree *); extern bool vrp_bitmap_equal_p (const_bitmap, const_bitmap); @@ -267,7 +269,6 @@ extern int compare_values_warnv (tree, tree, bool *); extern int operand_less_p (tree, tree); extern bool vrp_val_is_min (const_tree); extern bool vrp_val_is_max (const_tree); -extern int value_inside_range (tree, tree, tree); extern tree vrp_val_min (const_tree); extern tree vrp_val_max (const_tree); @@ -300,7 +301,11 @@ extern value_range_kind determine_value_range (tree, wide_int *, wide_int *); inline bool range_includes_zero_p (const value_range_base *vr) { - return range_includes_p (vr, 0); + /* ?? I'm not convinced we should return TRUE for undefined. */ + /* Short-circuit these because they don't have a type. */ + if (vr->undefined_p () || vr->varying_p ()) + return true; + return vr->contains_p (build_zero_cst (vr->type ())); } #endif /* GCC_TREE_VRP_H */ diff --git a/gcc/vr-values.c b/gcc/vr-values.c index 1c05ffb7f17..77b036a8ae6 100644 --- a/gcc/vr-values.c +++ b/gcc/vr-values.c @@ -1626,8 +1626,7 @@ compare_range_with_value (enum tree_code comp, value_range *vr, tree val, || comp == LE_EXPR) return NULL_TREE; - /* ~[VAL_1, VAL_2] OP VAL is known if VAL_1 <= VAL <= VAL_2. */ - if (value_inside_range (val, vr->min (), vr->max ()) == 1) + if (!vr->contains_p (val)) return (comp == NE_EXPR) ? boolean_true_node : boolean_false_node; return NULL_TREE;