From patchwork Wed Apr 26 11:47:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 68292 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 45979384F020 for ; Wed, 26 Apr 2023 11:49:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 45979384F020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682509778; bh=mn5CItVT8w0EVwb7fAOUmkDYlRiJJb8e9vTIoz3X/V0=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ir1ke6P4Gj7kWnSh3QPq0mgCHOA1M5dKAzClLLR90NIvxuxtXYOkWOzwX+VY5KkJi 0MnwaJgO4eEnN67auhHOafv48t9Dq4hBoIIEgemktsH3PAmYrQOJJsTj2/aCY8hUs5 3xgn0b4Of89yba2gRPvc+/w5wcrYQg9K5d3k3oRo= 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 8A7F43858C66 for ; Wed, 26 Apr 2023 11:48:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A7F43858C66 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-304-YiN1oAynO6C1TxqhZeCG3w-1; Wed, 26 Apr 2023 07:47:58 -0400 X-MC-Unique: YiN1oAynO6C1TxqhZeCG3w-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A3DB610146E9 for ; Wed, 26 Apr 2023 11:47:58 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.195.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B046C15BA0; Wed, 26 Apr 2023 11:47:58 +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 33QBlunS336970 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 26 Apr 2023 13:47:56 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 33QBluDn336969; Wed, 26 Apr 2023 13:47:56 +0200 To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] Remove range_int_cst_p. Date: Wed, 26 Apr 2023 13:47:50 +0200 Message-Id: <20230426114752.336928-5-aldyh@redhat.com> In-Reply-To: <20230426114752.336928-1-aldyh@redhat.com> References: <20230426114752.336928-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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, RCVD_IN_MSPIKE_H2, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" gcc/ChangeLog: * tree-data-ref.cc (compute_distributive_range): Replace uses of range_int_cst_p with irange API. * tree-ssa-strlen.cc (get_range_strlen_dynamic): Same. * tree-vrp.h (range_int_cst_p): Delete. * vr-values.cc (check_for_binary_op_overflow): Replace usees of range_int_cst_p with irange API. (vr_set_zero_nonzero_bits): Same. (range_fits_type_p): Same. (simplify_using_ranges::simplify_casted_cond): Same. --- gcc/tree-data-ref.cc | 3 ++- gcc/tree-ssa-strlen.cc | 28 ++++++++++---------- gcc/tree-vrp.cc | 9 ------- gcc/tree-vrp.h | 2 -- gcc/vr-values.cc | 59 ++++++++++++++++++++++-------------------- 5 files changed, 48 insertions(+), 53 deletions(-) diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc index 6a4112b9fde..b3a1d410cbd 100644 --- a/gcc/tree-data-ref.cc +++ b/gcc/tree-data-ref.cc @@ -646,7 +646,8 @@ compute_distributive_range (tree type, value_range &op0_range, if (!op.fold_range (wide_range, ssizetype, op0_range, op1_range)) wide_range.set_varying (ssizetype);; flag_wrapv = saved_flag_wrapv; - if (wide_range.num_pairs () != 1 || !range_int_cst_p (&wide_range)) + if (wide_range.num_pairs () != 1 + || wide_range.varying_p () || wide_range.undefined_p ()) return false; wide_int lb = wide_range.lower_bound (); diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc index de785281b27..4bf183072d9 100644 --- a/gcc/tree-ssa-strlen.cc +++ b/gcc/tree-ssa-strlen.cc @@ -1222,13 +1222,14 @@ get_range_strlen_dynamic (tree src, gimple *stmt, { value_range vr; ptr_qry->rvals->range_of_expr (vr, si->nonzero_chars, si->stmt); - if (range_int_cst_p (&vr)) + if (vr.undefined_p () || vr.varying_p ()) + pdata->minlen = build_zero_cst (size_type_node); + else { - pdata->minlen = vr.min (); - pdata->maxlen = vr.max (); + tree type = vr.type (); + pdata->minlen = wide_int_to_tree (type, vr.lower_bound ()); + pdata->maxlen = wide_int_to_tree (type, vr.upper_bound ()); } - else - pdata->minlen = build_zero_cst (size_type_node); } else pdata->minlen = build_zero_cst (size_type_node); @@ -1266,21 +1267,22 @@ get_range_strlen_dynamic (tree src, gimple *stmt, { value_range vr; ptr_qry->rvals->range_of_expr (vr, si->nonzero_chars, stmt); - if (range_int_cst_p (&vr)) + if (vr.varying_p () || vr.undefined_p ()) + { + pdata->minlen = build_zero_cst (size_type_node); + pdata->maxlen = build_all_ones_cst (size_type_node); + } + else { - pdata->minlen = vr.min (); - pdata->maxlen = vr.max (); + tree type = vr.type (); + pdata->minlen = wide_int_to_tree (type, vr.lower_bound ()); + pdata->maxlen = wide_int_to_tree (type, vr.upper_bound ()); offset_int max = offset_int::from (vr.upper_bound (0), SIGNED); if (tree maxbound = get_maxbound (si->ptr, stmt, max, ptr_qry)) pdata->maxbound = maxbound; else pdata->maxbound = pdata->maxlen; } - else - { - pdata->minlen = build_zero_cst (size_type_node); - pdata->maxlen = build_all_ones_cst (size_type_node); - } } else if (pdata->minlen && TREE_CODE (pdata->minlen) == INTEGER_CST) { diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc index 27126088708..6c6e0382809 100644 --- a/gcc/tree-vrp.cc +++ b/gcc/tree-vrp.cc @@ -312,15 +312,6 @@ intersect_range_with_nonzero_bits (enum value_range_kind vr_type, return vr_type; } -/* Return true if max and min of VR are INTEGER_CST. It's not necessary - a singleton. */ - -bool -range_int_cst_p (const value_range *vr) -{ - return (vr->kind () == VR_RANGE && range_has_numeric_bounds_p (vr)); -} - /* Return the single symbol (an SSA_NAME) contained in T if any, or NULL_TREE otherwise. We only handle additive operations and set NEG to true if the symbol is negated and INV to the invariant part, if any. */ diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h index bad50e31aad..58216388ee6 100644 --- a/gcc/tree-vrp.h +++ b/gcc/tree-vrp.h @@ -22,8 +22,6 @@ along with GCC; see the file COPYING3. If not see #include "value-range.h" -extern bool range_int_cst_p (const value_range *); - extern int compare_values (tree, tree); extern int compare_values_warnv (tree, tree, bool *); extern int operand_less_p (tree, tree); diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc index f43de63b4f4..ea7c6738739 100644 --- a/gcc/vr-values.cc +++ b/gcc/vr-values.cc @@ -125,16 +125,16 @@ check_for_binary_op_overflow (range_query *query, vr1.set_varying (TREE_TYPE (op1)); tree vr0min, vr0max, vr1min, vr1max; - get_legacy_range (vr0, vr0min, vr0max); - get_legacy_range (vr1, vr1min, vr1max); - if (!range_int_cst_p (&vr0) + value_range_kind kind0 = get_legacy_range (vr0, vr0min, vr0max); + value_range_kind kind1 = get_legacy_range (vr1, vr1min, vr1max); + if (kind0 != VR_RANGE || TREE_OVERFLOW (vr0min) || TREE_OVERFLOW (vr0max)) { vr0min = vrp_val_min (TREE_TYPE (op0)); vr0max = vrp_val_max (TREE_TYPE (op0)); } - if (!range_int_cst_p (&vr1) + if (kind1 != VR_RANGE || TREE_OVERFLOW (vr1min) || TREE_OVERFLOW (vr1max)) { @@ -1000,10 +1000,11 @@ simplify_using_ranges::simplify_div_or_mod_using_ranges { if (!query->range_of_expr (vr, op0, stmt)) vr.set_varying (TREE_TYPE (op0)); - if (range_int_cst_p (&vr)) + if (!vr.varying_p () && !vr.undefined_p ()) { - op0min = vr.min (); - op0max = vr.max (); + tree type = vr.type (); + op0min = wide_int_to_tree (type, vr.lower_bound ()); + op0max = wide_int_to_tree (type, vr.upper_bound ()); } } @@ -1013,8 +1014,8 @@ simplify_using_ranges::simplify_div_or_mod_using_ranges value_range vr1; if (!query->range_of_expr (vr1, op1, stmt)) vr1.set_varying (TREE_TYPE (op1)); - if (range_int_cst_p (&vr1)) - op1min = vr1.min (); + if (!vr1.varying_p () && !vr1.undefined_p ()) + op1min = wide_int_to_tree (vr1.type (), vr1.lower_bound ()); } if (rhs_code == TRUNC_MOD_EXPR && TREE_CODE (op1min) == INTEGER_CST @@ -1217,21 +1218,19 @@ simplify_using_ranges::simplify_abs_using_ranges (gimple_stmt_iterator *gsi, static bool vr_set_zero_nonzero_bits (const tree expr_type, - const value_range *vr, + const irange *vr, wide_int *may_be_nonzero, wide_int *must_be_nonzero) { - if (range_int_cst_p (vr)) + if (vr->varying_p () || vr->undefined_p ()) { - wi_set_zero_nonzero_bits (expr_type, - wi::to_wide (vr->min ()), - wi::to_wide (vr->max ()), - *may_be_nonzero, *must_be_nonzero); - return true; + *may_be_nonzero = wi::minus_one (TYPE_PRECISION (expr_type)); + *must_be_nonzero = wi::zero (TYPE_PRECISION (expr_type)); + return false; } - *may_be_nonzero = wi::minus_one (TYPE_PRECISION (expr_type)); - *must_be_nonzero = wi::zero (TYPE_PRECISION (expr_type)); - return false; + wi_set_zero_nonzero_bits (expr_type, vr->lower_bound (), vr->upper_bound (), + *may_be_nonzero, *must_be_nonzero); + return true; } /* Optimize away redundant BIT_AND_EXPR and BIT_IOR_EXPR. @@ -1418,7 +1417,9 @@ range_fits_type_p (const value_range *vr, return true; /* Now we can only handle ranges with constant bounds. */ - if (!range_int_cst_p (vr)) + tree vrmin, vrmax; + value_range_kind kind = get_legacy_range (*vr, vrmin, vrmax); + if (kind != VR_RANGE) return false; /* For sign changes, the MSB of the wide_int has to be clear. @@ -1426,17 +1427,17 @@ range_fits_type_p (const value_range *vr, a signed wide_int, while a negative value cannot be represented by an unsigned wide_int. */ if (src_sgn != dest_sgn - && (wi::lts_p (wi::to_wide (vr->min ()), 0) - || wi::lts_p (wi::to_wide (vr->max ()), 0))) + && (wi::lts_p (wi::to_wide (vrmin), 0) + || wi::lts_p (wi::to_wide (vrmax), 0))) return false; /* Then we can perform the conversion on both ends and compare the result for equality. */ - tem = wi::ext (wi::to_widest (vr->min ()), dest_precision, dest_sgn); - if (tem != wi::to_widest (vr->min ())) + tem = wi::ext (wi::to_widest (vrmin), dest_precision, dest_sgn); + if (tem != wi::to_widest (vrmin)) return false; - tem = wi::ext (wi::to_widest (vr->max ()), dest_precision, dest_sgn); - if (tem != wi::to_widest (vr->max ())) + tem = wi::ext (wi::to_widest (vrmax), dest_precision, dest_sgn); + if (tem != wi::to_widest (vrmax)) return false; return true; @@ -1682,7 +1683,8 @@ simplify_using_ranges::simplify_casted_cond (gcond *stmt) value_range vr; if (query->range_of_expr (vr, innerop) - && range_int_cst_p (&vr) + && !vr.varying_p () + && !vr.undefined_p () && range_fits_type_p (&vr, TYPE_PRECISION (TREE_TYPE (op0)), TYPE_SIGN (TREE_TYPE (op0))) @@ -2024,7 +2026,8 @@ simplify_using_ranges::simplify_float_conversion_using_ranges /* We can only handle constant ranges. */ if (!query->range_of_expr (vr, rhs1, stmt) - || !range_int_cst_p (&vr)) + || vr.varying_p () + || vr.undefined_p ()) return false; /* First check if we can use a signed type in place of an unsigned. */