From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 78CD0385701A for ; Mon, 26 Jul 2021 11:43:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 78CD0385701A 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-297-sacyRkhLOf2xPDtQGlKljQ-1; Mon, 26 Jul 2021 07:43:02 -0400 X-MC-Unique: sacyRkhLOf2xPDtQGlKljQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1DC0E801B3C for ; Mon, 26 Jul 2021 11:42:47 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A415260853; Mon, 26 Jul 2021 11:42:46 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.16.1/8.15.2) with ESMTPS id 16QBgiii2402605 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 26 Jul 2021 13:42:44 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 16QBghTY2402604; Mon, 26 Jul 2021 13:42:43 +0200 From: Aldy Hernandez To: GCC patches Subject: [PUSHED] Abstract out conditional simplification out of execute_vrp. Date: Mon, 26 Jul 2021 13:42:33 +0200 Message-Id: <20210726114233.2402554-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-13.3 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Mon, 26 Jul 2021 11:43:06 -0000 VRP simplifies conditionals involving casted values outside of the main folding mechanism, because this optimization inhibits the VRP jump threader from threading through the comparison. As part of replacing VRP with an evrp instance, I am making sure we do everything VRP does. Hence, I am abstracting this functionality out so we can call it from from elsewhere. ISTM that when the proposed ranger-based jump threader can handle everything the forward threader does, there will be no need for this optimization to be done outside of the evrp folder. Perhaps we can fold this into the substitute_using_ranges class. But that's further down the line. Also, there is no need to pass a vr_values around, when the base range_query class will do. I fixed this, at it makes it trivial to pass down a ranger or evrp instance. Tested on x86-64 Linux. gcc/ChangeLog: * tree-vrp.c (vrp_simplify_cond_using_ranges): Rename vr_values with range_query. (execute_vrp): Abstract out simplification of conditionals... (simplify_casted_conds): ...here. --- gcc/tree-vrp.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index a9c31bcedb5..58111f83183 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -4359,7 +4359,7 @@ vrp_jump_threader::after_dom_children (basic_block bb) subsequent passes. */ static void -vrp_simplify_cond_using_ranges (vr_values *query, gcond *stmt) +vrp_simplify_cond_using_ranges (range_query *query, gcond *stmt) { tree op0 = gimple_cond_lhs (stmt); tree op1 = gimple_cond_rhs (stmt); @@ -4423,6 +4423,27 @@ vrp_simplify_cond_using_ranges (vr_values *query, gcond *stmt) } } +/* A comparison of an SSA_NAME against a constant where the SSA_NAME + was set by a type conversion can often be rewritten to use the RHS + of the type conversion. Do this optimization for all conditionals + in FUN. + + However, doing so inhibits jump threading through the comparison. + So that transformation is not performed until after jump threading + is complete. */ + +static void +simplify_casted_conds (function *fun, range_query *query) +{ + basic_block bb; + FOR_EACH_BB_FN (bb, fun) + { + gimple *last = last_stmt (bb); + if (last && gimple_code (last) == GIMPLE_COND) + vrp_simplify_cond_using_ranges (query, as_a (last)); + } +} + /* 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 @@ -4519,21 +4540,7 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p) vrp_jump_threader threader (fun, &vrp_vr_values); threader.thread_jumps (); - /* A comparison of an SSA_NAME against a constant where the SSA_NAME - was set by a type conversion can often be rewritten to use the - RHS of the type conversion. - - However, doing so inhibits jump threading through the comparison. - So that transformation is not performed until after jump threading - is complete. */ - basic_block bb; - FOR_EACH_BB_FN (bb, fun) - { - gimple *last = last_stmt (bb); - if (last && gimple_code (last) == GIMPLE_COND) - vrp_simplify_cond_using_ranges (&vrp_vr_values, - as_a (last)); - } + simplify_casted_conds (fun, &vrp_vr_values); free_numbers_of_iterations_estimates (fun); -- 2.31.1