From patchwork Tue Nov 5 09:51:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1189483 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-512413-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="EK86M5Di"; 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 476lLL5c72z9s4Y for ; Tue, 5 Nov 2019 20:51:37 +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:from :subject:to:cc:message-id:date:mime-version:content-type; q=dns; s=default; b=VScn2L8DbN6pFLNy2FxLN6/eOgeo4orfuYZHY3rmYu2r8qqnT8 jE0QJeR/oGVnHsimygrfYQbtSkFh2iAUPaTTAetNmX3WFZRDUOZVfGwpVXADhoNz 5DrtDqAvl9JK5sVi0tXdqSmTaMSsuQzKPoxtOxXWeoPnYHipxQYf0Uf7U= 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:cc:message-id:date:mime-version:content-type; s= default; bh=H4x11MW+XWfNYT5vBDyItXL7WvI=; b=EK86M5DiO2hb8CY2P2HS QT37J50IeRdSJiBfpa4yjJKPsWg7s9u0LwA/yao7TqNhCMsaC1834U06jMUwAVju kNW85/JtA8VSoPLF/e700E6++CHgL/HR49SfMwzu2O/PLbwpKSOJh51GEhN179g7 TjfUFOuZEIwN1XTs4Z+3jNg= Received: (qmail 47299 invoked by alias); 5 Nov 2019 09:51:30 -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 47290 invoked by uid 89); 5 Nov 2019 09:51:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy= 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; Tue, 05 Nov 2019 09:51:28 +0000 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (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 93F9A81F10 for ; Tue, 5 Nov 2019 09:51:26 +0000 (UTC) Received: by mail-wr1-f69.google.com with SMTP id w4so3607188wro.10 for ; Tue, 05 Nov 2019 01:51:26 -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 b8sm13208557wrt.39.2019.11.05.01.51.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Nov 2019 01:51:24 -0800 (PST) From: Aldy Hernandez Subject: [committed] move vrp_set_zero_nonzero_bits into vr-values.c To: gcc-patches Cc: Andrew MacLeod Message-ID: <5fe14bcd-d21c-6838-1b7d-9f612925b155@redhat.com> Date: Tue, 5 Nov 2019 10:51:23 +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 This function is only used in vr-values.c, so it doesn't need to be externally visible or defined in tree-vrp.c. In moving it I noticed that wide_int_range_set_zero_nonzero_bits is redundant, as we can grab the version in range-op. I've also renamed the function to vr_set_zero_nonzero_bits (removed the "P"), as it's more a value_range thing than a VRP thing. Committed as obvious. commit a59ec913fa95849a356d00d211510b29eab5565f Author: Aldy Hernandez Date: Tue Nov 5 09:48:41 2019 +0100 Move vrp_set_zero_nonzero_bits from tree-vrp.c into vr-values.c, and make it use wi_set_zero_nonzero_bits. Remove the now redundant wide_int_range_set_zero_nonzero_bits. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f492ea6da0c..786dee727dc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2019-11-05 Aldy Hernandez + + * range-op.cc (wi_set_zero_nonzero_bits): Remove static qualifier. + * range-op.h (wi_set_zero_nonzero_bits): New prototype. + * tree-vrp.h (vrp_set_zero_nonzero_bits): Remove. + * tree-vrp.c (wide_int_range_set_zero_nonzero_bits): Remove. + (vrp_set_zero_nonzero_bits): Move to... + * vr-values.c (vr_set_zero_nonzero_bits): ...here. + (vr_values::simplify_bit_ops_using_ranges): Rename + vrp_set_zero_nonzero_bits to vr_set_zero_nonzero_bits. + 2019-11-05 Aldy Hernandez * tree-vrp.h (vrp_bitmap_equal_p): Remove. diff --git a/gcc/range-op.cc b/gcc/range-op.cc index fc31485384b..56e8a20ad9e 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1847,7 +1847,7 @@ wi_optimize_and_or (value_range_base &r, // for all numbers in the range the bit is 1, otherwise it might be 0 // or 1. -static void +void wi_set_zero_nonzero_bits (tree type, const wide_int &lb, const wide_int &ub, wide_int &maybe_nonzero, diff --git a/gcc/range-op.h b/gcc/range-op.h index f6510758163..e531b918263 100644 --- a/gcc/range-op.h +++ b/gcc/range-op.h @@ -82,7 +82,10 @@ protected: }; extern range_operator *range_op_handler (enum tree_code code, tree type); - extern void range_cast (value_range_base &, tree type); +extern void wi_set_zero_nonzero_bits (tree type, + const wide_int &, const wide_int &, + wide_int &maybe_nonzero, + wide_int &mustbe_nonzero); #endif // GCC_RANGE_OP_H diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index e926670b962..e1d5c7cb98c 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -1260,69 +1260,6 @@ value_range_base::value_inside_range (tree val) const return !!cmp2; } -/* For range [LB, UB] compute two wide_int bit masks. - - In the MAY_BE_NONZERO bit mask, if some bit is unset, it means that - for all numbers in the range the bit is 0, otherwise it might be 0 - or 1. - - In the MUST_BE_NONZERO bit mask, if some bit is set, it means that - for all numbers in the range the bit is 1, otherwise it might be 0 - or 1. */ - -static inline void -wide_int_range_set_zero_nonzero_bits (signop sign, - const wide_int &lb, const wide_int &ub, - wide_int &may_be_nonzero, - wide_int &must_be_nonzero) -{ - may_be_nonzero = wi::minus_one (lb.get_precision ()); - must_be_nonzero = wi::zero (lb.get_precision ()); - - if (wi::eq_p (lb, ub)) - { - may_be_nonzero = lb; - must_be_nonzero = may_be_nonzero; - } - else if (wi::ge_p (lb, 0, sign) || wi::lt_p (ub, 0, sign)) - { - wide_int xor_mask = lb ^ ub; - may_be_nonzero = lb | ub; - must_be_nonzero = lb & ub; - if (xor_mask != 0) - { - wide_int mask = wi::mask (wi::floor_log2 (xor_mask), false, - may_be_nonzero.get_precision ()); - may_be_nonzero = may_be_nonzero | mask; - must_be_nonzero = wi::bit_and_not (must_be_nonzero, mask); - } - } -} - -/* value_range wrapper for wide_int_range_set_zero_nonzero_bits above. - - Return TRUE if VR was a constant range and we were able to compute - the bit masks. */ - -bool -vrp_set_zero_nonzero_bits (const tree expr_type, - const value_range_base *vr, - wide_int *may_be_nonzero, - wide_int *must_be_nonzero) -{ - if (!range_int_cst_p (vr)) - { - *may_be_nonzero = wi::minus_one (TYPE_PRECISION (expr_type)); - *must_be_nonzero = wi::zero (TYPE_PRECISION (expr_type)); - return false; - } - wide_int_range_set_zero_nonzero_bits (TYPE_SIGN (expr_type), - wi::to_wide (vr->min ()), - wi::to_wide (vr->max ()), - *may_be_nonzero, *must_be_nonzero); - return true; -} - /* Create two value-ranges in *VR0 and *VR1 from the anti-range *AR so that *VR0 U *VR1 == *AR. Returns true if that is possible, false otherwise. If *AR can be represented with a single range diff --git a/gcc/tree-vrp.h b/gcc/tree-vrp.h index 3861634fb7e..0bf33caba85 100644 --- a/gcc/tree-vrp.h +++ b/gcc/tree-vrp.h @@ -299,8 +299,6 @@ void range_fold_binary_expr (value_range_base *, enum tree_code, tree type, extern bool vrp_operand_equal_p (const_tree, const_tree); extern enum value_range_kind intersect_range_with_nonzero_bits (enum value_range_kind, wide_int *, wide_int *, const wide_int &, signop); -extern bool vrp_set_zero_nonzero_bits (const tree, const value_range_base *, - wide_int *, wide_int *); extern bool find_case_label_range (gswitch *, tree, tree, size_t *, size_t *); extern bool find_case_label_index (gswitch *, size_t, tree, size_t *); diff --git a/gcc/vr-values.c b/gcc/vr-values.c index 3acbfc60797..d1713bf4e0e 100644 --- a/gcc/vr-values.c +++ b/gcc/vr-values.c @@ -3341,6 +3341,30 @@ vr_values::simplify_abs_using_ranges (gimple_stmt_iterator *gsi, gimple *stmt) return false; } +/* value_range wrapper for wi_set_zero_nonzero_bits. + + Return TRUE if VR was a constant range and we were able to compute + the bit masks. */ + +static bool +vr_set_zero_nonzero_bits (const tree expr_type, + const value_range_base *vr, + wide_int *may_be_nonzero, + wide_int *must_be_nonzero) +{ + if (range_int_cst_p (vr)) + { + 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; +} + /* Optimize away redundant BIT_AND_EXPR and BIT_IOR_EXPR. If all the bits that are being cleared by & are already known to be zero from VR, or all the bits that are being @@ -3373,11 +3397,11 @@ vr_values::simplify_bit_ops_using_ranges (gimple_stmt_iterator *gsi, else return false; - if (!vrp_set_zero_nonzero_bits (TREE_TYPE (op0), &vr0, &may_be_nonzero0, - &must_be_nonzero0)) + if (!vr_set_zero_nonzero_bits (TREE_TYPE (op0), &vr0, &may_be_nonzero0, + &must_be_nonzero0)) return false; - if (!vrp_set_zero_nonzero_bits (TREE_TYPE (op1), &vr1, &may_be_nonzero1, - &must_be_nonzero1)) + if (!vr_set_zero_nonzero_bits (TREE_TYPE (op1), &vr1, &may_be_nonzero1, + &must_be_nonzero1)) return false; switch (gimple_assign_rhs_code (stmt))