From patchwork Wed Oct 21 07:51:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1385419 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Nu7C/TSM; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CGN4Y5P92z9sPB for ; Wed, 21 Oct 2020 18:52:10 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 012C13861810; Wed, 21 Oct 2020 07:52:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 012C13861810 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1603266728; bh=pbIMBcZqYspeusNORJz49mVnXGUWGawZl7RJtcnxkEY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Nu7C/TSM0/mntJJ5uI8bGN2B2GE2oLFZ/A81/ug/X/3lBDQof3gvB+aaetcqxrKH5 XqS0YDF9KHr4uJJ8T0UJH0xwr4yV4T6wvbwND2MGDhlbFNnxIJMBEOV0SwrygrEqgv ZF7AbhW7raWn+h16qLv/51psF6S+M0z3GQOb/UVA= 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 [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 0ACE13858D37 for ; Wed, 21 Oct 2020 07:52:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0ACE13858D37 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-sakYI8aaPb6_ZNz9POOtxA-1; Wed, 21 Oct 2020 03:52:02 -0400 X-MC-Unique: sakYI8aaPb6_ZNz9POOtxA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7602064091 for ; Wed, 21 Oct 2020 07:52:01 +0000 (UTC) Received: from abulafia.quesejoda.com (ovpn-114-39.ams2.redhat.com [10.36.114.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 073E15C1BB; Wed, 21 Oct 2020 07:52:00 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.15.2/8.15.2) with ESMTPS id 09L7pwhb052853 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 21 Oct 2020 09:51:58 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.15.2/8.15.2/Submit) id 09L7pvKw052852; Wed, 21 Oct 2020 09:51:57 +0200 To: GCC patches Subject: [PATCH] Move simplify_cond_using_ranges_2 to tree-vrp.c Date: Wed, 21 Oct 2020 09:51:50 +0200 Message-Id: <20201021075150.52799-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.2 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_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" This was slated to be moved last year, as its only use is in tree-vrp.c There are no functional changes. It's just a move and a rename. Pushed. gcc/ChangeLog: * vr-values.h: Remove simplify_cond_using_ranges_2. (range_fits_type_p): New. * vr-values.c (range_fits_type_p): Remove static qualifier. (vrp_simplify_cond_using_ranges): Move... * tree-vrp.c (vrp_simplify_cond_using_ranges): ...to here. --- gcc/tree-vrp.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++-- gcc/vr-values.c | 63 +---------------------------------------------- gcc/vr-values.h | 5 ++-- 3 files changed, 66 insertions(+), 67 deletions(-) diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 0e19690f41f..e00c034fee3 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -4395,6 +4395,67 @@ vrp_prop::vrp_finalize (vrp_folder *folder, bool warn_array_bounds_p) } } +/* STMT is a conditional at the end of a basic block. + + If the conditional is of the form SSA_NAME op constant and the SSA_NAME + was set via a type conversion, try to replace the SSA_NAME with the RHS + of the type conversion. Doing so makes the conversion dead which helps + subsequent passes. */ + +static void +vrp_simplify_cond_using_ranges (vr_values *query, gcond *stmt) +{ + tree op0 = gimple_cond_lhs (stmt); + tree op1 = gimple_cond_rhs (stmt); + + /* If we have a comparison of an SSA_NAME (OP0) against a constant, + see if OP0 was set by a type conversion where the source of + the conversion is another SSA_NAME with a range that fits + into the range of OP0's type. + + If so, the conversion is redundant as the earlier SSA_NAME can be + used for the comparison directly if we just massage the constant in the + comparison. */ + if (TREE_CODE (op0) == SSA_NAME + && TREE_CODE (op1) == INTEGER_CST) + { + gimple *def_stmt = SSA_NAME_DEF_STMT (op0); + tree innerop; + + if (!is_gimple_assign (def_stmt) + || !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt))) + return; + + innerop = gimple_assign_rhs1 (def_stmt); + + if (TREE_CODE (innerop) == SSA_NAME + && !POINTER_TYPE_P (TREE_TYPE (innerop)) + && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (innerop) + && desired_pro_or_demotion_p (TREE_TYPE (innerop), TREE_TYPE (op0))) + { + const value_range *vr = query->get_value_range (innerop); + + if (range_int_cst_p (vr) + && range_fits_type_p (vr, + TYPE_PRECISION (TREE_TYPE (op0)), + TYPE_SIGN (TREE_TYPE (op0))) + && int_fits_type_p (op1, TREE_TYPE (innerop))) + { + tree newconst = fold_convert (TREE_TYPE (innerop), op1); + gimple_cond_set_lhs (stmt, innerop); + gimple_cond_set_rhs (stmt, newconst); + update_stmt (stmt); + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Folded into: "); + print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); + fprintf (dump_file, "\n"); + } + } + } + } +} + /* Main entry point to VRP (Value Range Propagation). This pass is loosely based on J. R. C. Patterson, ``Accurate Static Branch Prediction by Value Range Propagation,'' in SIGPLAN Conference on @@ -4482,8 +4543,8 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p) { gimple *last = last_stmt (bb); if (last && gimple_code (last) == GIMPLE_COND) - simplify_cond_using_ranges_2 (&vrp_prop.vr_values, - as_a (last)); + vrp_simplify_cond_using_ranges (&vrp_prop.vr_values, + as_a (last)); } free_numbers_of_iterations_estimates (fun); diff --git a/gcc/vr-values.c b/gcc/vr-values.c index 67c88006f13..cc0ddca2bd3 100644 --- a/gcc/vr-values.c +++ b/gcc/vr-values.c @@ -3594,7 +3594,7 @@ test_for_singularity (enum tree_code cond_code, tree op0, /* Return whether the value range *VR fits in an integer type specified by PRECISION and UNSIGNED_P. */ -static bool +bool range_fits_type_p (const value_range *vr, unsigned dest_precision, signop dest_sgn) { @@ -3781,67 +3781,6 @@ simplify_using_ranges::simplify_cond_using_ranges_1 (gcond *stmt) return false; } -/* STMT is a conditional at the end of a basic block. - - If the conditional is of the form SSA_NAME op constant and the SSA_NAME - was set via a type conversion, try to replace the SSA_NAME with the RHS - of the type conversion. Doing so makes the conversion dead which helps - subsequent passes. */ - -void -simplify_cond_using_ranges_2 (vr_values *query, gcond *stmt) -{ - tree op0 = gimple_cond_lhs (stmt); - tree op1 = gimple_cond_rhs (stmt); - - /* If we have a comparison of an SSA_NAME (OP0) against a constant, - see if OP0 was set by a type conversion where the source of - the conversion is another SSA_NAME with a range that fits - into the range of OP0's type. - - If so, the conversion is redundant as the earlier SSA_NAME can be - used for the comparison directly if we just massage the constant in the - comparison. */ - if (TREE_CODE (op0) == SSA_NAME - && TREE_CODE (op1) == INTEGER_CST) - { - gimple *def_stmt = SSA_NAME_DEF_STMT (op0); - tree innerop; - - if (!is_gimple_assign (def_stmt) - || !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt))) - return; - - innerop = gimple_assign_rhs1 (def_stmt); - - if (TREE_CODE (innerop) == SSA_NAME - && !POINTER_TYPE_P (TREE_TYPE (innerop)) - && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (innerop) - && desired_pro_or_demotion_p (TREE_TYPE (innerop), TREE_TYPE (op0))) - { - const value_range *vr = query->get_value_range (innerop); - - if (range_int_cst_p (vr) - && range_fits_type_p (vr, - TYPE_PRECISION (TREE_TYPE (op0)), - TYPE_SIGN (TREE_TYPE (op0))) - && int_fits_type_p (op1, TREE_TYPE (innerop))) - { - tree newconst = fold_convert (TREE_TYPE (innerop), op1); - gimple_cond_set_lhs (stmt, innerop); - gimple_cond_set_rhs (stmt, newconst); - update_stmt (stmt); - if (dump_file && (dump_flags & TDF_DETAILS)) - { - fprintf (dump_file, "Folded into: "); - print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); - fprintf (dump_file, "\n"); - } - } - } - } -} - /* Simplify a switch statement using the value range of the switch argument. */ diff --git a/gcc/vr-values.h b/gcc/vr-values.h index b0ff68d8e34..59fac0c4b1e 100644 --- a/gcc/vr-values.h +++ b/gcc/vr-values.h @@ -170,9 +170,8 @@ class vr_values : public range_query extern tree get_output_for_vrp (gimple *); -// FIXME: Move this to tree-vrp.c. -void simplify_cond_using_ranges_2 (class vr_values *, gcond *); - +extern bool range_fits_type_p (const value_range *vr, + unsigned dest_precision, signop dest_sgn); extern bool bounds_of_var_in_loop (tree *min, tree *max, range_query *, class loop *loop, gimple *stmt, tree var);