From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1984) id 83DB03858CDB; Wed, 18 Oct 2023 08:04:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 83DB03858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697616248; bh=md7DoI4MvkhzI4CIbVCNkIDdYvCBRZAV+CI6tlZQjUo=; h=From:To:Subject:Date:From; b=CbPKwwN//3EADfiN8OyCsTn1TqtGEoPsDUigvUo6T/FdF2U4Rc3OZ8SJ2RcFdnZp2 /WnURR7HMXUHGUhr0YkSVtIiIKujLx52hoxI3L3jZvME/2EHaHRuMWgRY/lgs9sy6m ZfA4Wd7oQkSmSToqhewdJh3KA2fJFS+/p5H0YKdo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Tamar Christina To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4707] middle-end: refactor vectorizable_comparison to make the main body re-usable. X-Act-Checkin: gcc X-Git-Author: Tamar Christina X-Git-Refname: refs/heads/master X-Git-Oldrev: c51040cb43404f411d4234abe7cf1a238b6e0d34 X-Git-Newrev: 46937e1b47274c5f5edfc22c7e70b820c6d55530 Message-Id: <20231018080408.83DB03858CDB@sourceware.org> Date: Wed, 18 Oct 2023 08:04:08 +0000 (GMT) List-Id: https://gcc.gnu.org/g:46937e1b47274c5f5edfc22c7e70b820c6d55530 commit r14-4707-g46937e1b47274c5f5edfc22c7e70b820c6d55530 Author: Tamar Christina Date: Wed Oct 18 09:01:41 2023 +0100 middle-end: refactor vectorizable_comparison to make the main body re-usable. Vectorization of a gcond starts off essentially the same as vectorizing a comparison witht he only difference being how the operands are extracted. This refactors vectorable_comparison such that we now have a generic function that can be used from vectorizable_early_break. The refactoring splits the gassign checks and actual validation/codegen off to a helper function. No change in functionality expected. gcc/ChangeLog: * tree-vect-stmts.cc (vectorizable_comparison): Refactor, splitting body to ... (vectorizable_comparison_1): ...This. Diff: --- gcc/tree-vect-stmts.cc | 64 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 9bb43e98f56d..2974eb6a981b 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -12324,23 +12324,22 @@ vectorizable_condition (vec_info *vinfo, return true; } -/* vectorizable_comparison. +/* Helper of vectorizable_comparison. - Check if STMT_INFO is comparison expression that can be vectorized. + Check if STMT_INFO is comparison expression CODE that can be vectorized. If VEC_STMT is also passed, vectorize STMT_INFO: create a vectorized comparison, put it in VEC_STMT, and insert it at GSI. Return true if STMT_INFO is vectorizable in this way. */ static bool -vectorizable_comparison (vec_info *vinfo, - stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, - gimple **vec_stmt, - slp_tree slp_node, stmt_vector_for_cost *cost_vec) +vectorizable_comparison_1 (vec_info *vinfo, tree vectype, + stmt_vec_info stmt_info, tree_code code, + gimple_stmt_iterator *gsi, gimple **vec_stmt, + slp_tree slp_node, stmt_vector_for_cost *cost_vec) { tree lhs, rhs1, rhs2; tree vectype1 = NULL_TREE, vectype2 = NULL_TREE; - tree vectype = STMT_VINFO_VECTYPE (stmt_info); tree vec_rhs1 = NULL_TREE, vec_rhs2 = NULL_TREE; tree new_temp; loop_vec_info loop_vinfo = dyn_cast (vinfo); @@ -12348,7 +12347,7 @@ vectorizable_comparison (vec_info *vinfo, int ndts = 2; poly_uint64 nunits; int ncopies; - enum tree_code code, bitop1 = NOP_EXPR, bitop2 = NOP_EXPR; + enum tree_code bitop1 = NOP_EXPR, bitop2 = NOP_EXPR; int i; bb_vec_info bb_vinfo = dyn_cast (vinfo); vec vec_oprnds0 = vNULL; @@ -12371,14 +12370,6 @@ vectorizable_comparison (vec_info *vinfo, ncopies = vect_get_num_copies (loop_vinfo, vectype); gcc_assert (ncopies >= 1); - if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def) - return false; - - gassign *stmt = dyn_cast (stmt_info->stmt); - if (!stmt) - return false; - - code = gimple_assign_rhs_code (stmt); if (TREE_CODE_CLASS (code) != tcc_comparison) return false; @@ -12493,7 +12484,6 @@ vectorizable_comparison (vec_info *vinfo, return false; } - STMT_VINFO_TYPE (stmt_info) = comparison_vec_info_type; vect_model_simple_cost (vinfo, stmt_info, ncopies * (1 + (bitop2 != NOP_EXPR)), dts, ndts, slp_node, cost_vec); @@ -12503,7 +12493,7 @@ vectorizable_comparison (vec_info *vinfo, /* Transform. */ /* Handle def. */ - lhs = gimple_assign_lhs (stmt); + lhs = gimple_assign_lhs (STMT_VINFO_STMT (stmt_info)); mask = vect_create_destination_var (lhs, mask_type); vect_get_vec_defs (vinfo, stmt_info, slp_node, ncopies, @@ -12559,6 +12549,44 @@ vectorizable_comparison (vec_info *vinfo, return true; } +/* vectorizable_comparison. + + Check if STMT_INFO is comparison expression that can be vectorized. + If VEC_STMT is also passed, vectorize STMT_INFO: create a vectorized + comparison, put it in VEC_STMT, and insert it at GSI. + + Return true if STMT_INFO is vectorizable in this way. */ + +static bool +vectorizable_comparison (vec_info *vinfo, + stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, + gimple **vec_stmt, + slp_tree slp_node, stmt_vector_for_cost *cost_vec) +{ + bb_vec_info bb_vinfo = dyn_cast (vinfo); + + if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo) + return false; + + if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def) + return false; + + gassign *stmt = dyn_cast (stmt_info->stmt); + if (!stmt) + return false; + + enum tree_code code = gimple_assign_rhs_code (stmt); + tree vectype = STMT_VINFO_VECTYPE (stmt_info); + if (!vectorizable_comparison_1 (vinfo, vectype, stmt_info, code, gsi, + vec_stmt, slp_node, cost_vec)) + return false; + + if (!vec_stmt) + STMT_VINFO_TYPE (stmt_info) = comparison_vec_info_type; + + return true; +} + /* If SLP_NODE is nonnull, return true if vectorizable_live_operation can handle all live statements in the node. Otherwise return true if STMT_INFO is not live or if vectorizable_live_operation can handle it.