From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1923) id 78D193858C60; Wed, 17 Jan 2024 19:15:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78D193858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705518932; bh=4CKMqAKJ5+LeRjTvyKspeJKeafkzjyPNx00g9h/x5O8=; h=From:To:Subject:Date:From; b=OFqvtqVKTT8ZtZZvraS2jtIZD4BCcFEhUKCBw1G28/LbjdwJnVZ/hhikfjJEAV1ar ZmADvnCXTD/RvSYEXSZSwtH0UiIKW7GJrlgewek10Xxz4Zlx995xo8zVI9LxaBIHbk x6h2XKzPGhjhR2e1J0RqTuoiWxOaFmhUhCVeE7tw= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Philipp Tomsich To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/vrull/heads/slp-improvements)] Prorerly handle VIEW_CONVERT_EXPR in for NxM vector permute folding X-Act-Checkin: gcc X-Git-Author: Manolis Tsamis X-Git-Refname: refs/vendors/vrull/heads/slp-improvements X-Git-Oldrev: 926fbfaa3c8b3bde520bd89f0acd3ed9f69d28ce X-Git-Newrev: eacb8fdaaeffa77fb090ce24a5bd3d0b0dc66cb5 Message-Id: <20240117191532.78D193858C60@sourceware.org> Date: Wed, 17 Jan 2024 19:15:32 +0000 (GMT) List-Id: https://gcc.gnu.org/g:eacb8fdaaeffa77fb090ce24a5bd3d0b0dc66cb5 commit eacb8fdaaeffa77fb090ce24a5bd3d0b0dc66cb5 Author: Manolis Tsamis Date: Fri Dec 15 17:14:05 2023 +0100 Prorerly handle VIEW_CONVERT_EXPR in for NxM vector permute folding Ref #354 Diff: --- gcc/tree-vect-slp.cc | 76 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 67ca0ffc0da..c630ce5bbe0 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -8132,8 +8132,17 @@ get_perm_def (tree name, gassign **perm, gassign **def) return false; gassign *stmt2 = stmt1; - if (gimple_assign_rhs_code (stmt1) == VIEW_CONVERT_EXPR) - stmt2 = get_tree_def(TREE_OPERAND (gimple_assign_rhs1 (stmt1), 0), false); + + /* Look through a view convert if it doesn't change the vector's shape. */ + if (gimple_assign_rhs_code (stmt1) == VIEW_CONVERT_EXPR) { + tree vc = gimple_assign_rhs1(stmt1); + if (element_precision (TREE_TYPE (vc)) + == element_precision (TREE_TYPE (TREE_OPERAND (vc, 0)))) + stmt2 = get_tree_def (TREE_OPERAND (gimple_assign_rhs1 (stmt1), 0), + false); + else + return false; + } if (!stmt2) return false; @@ -8409,8 +8418,8 @@ vect_slp_optimize_permutes (function *fun) || !VECTOR_CST_NELTS (gimple_assign_rhs3 (perms[1])).is_constant ()) continue; - hash_set all_perms; - all_perms.add (stmt); + auto_vec all_perms; + all_perms.safe_push (stmt); tree def0_name = gimple_assign_lhs (defs[0]); tree def1_name = gimple_assign_lhs (defs[1]); @@ -8437,16 +8446,24 @@ vect_slp_optimize_permutes (function *fun) break; } - all_perms.add (use); + all_perms.safe_push (use); } if (!only_same_perms) continue; - for (hash_set ::iterator iter = all_perms.begin (); - iter != all_perms.end (); ++iter) + unsigned i; + gimple *iter; + + FOR_EACH_VEC_ELT (all_perms, i, iter) { - gassign *perm = dyn_cast (*iter); + gassign *perm = dyn_cast (iter); + + /* Check if we have already processed this permutation. */ + if (gimple_assign_rhs1 (perm) != def0_name + && gimple_assign_rhs1 (perm) != def1_name) + continue; + tree mask = gimple_assign_rhs3 (perm); unsigned HOST_WIDE_INT nelts = VECTOR_CST_NELTS (mask).to_constant (); @@ -8467,25 +8484,54 @@ vect_slp_optimize_permutes (function *fun) if (lane < nelts) new_lane = TREE_INT_CST_LOW (VECTOR_CST_ELT (mask1, lane)); else - new_lane = TREE_INT_CST_LOW (VECTOR_CST_ELT (mask2, lane - nelts)); + new_lane = TREE_INT_CST_LOW (VECTOR_CST_ELT (mask2, + lane - nelts)); sel.quick_push (new_lane); } vec_perm_indices indices (sel, 2, nelts); tree vectype = TREE_TYPE (gimple_assign_lhs (perm)); - if (!can_vec_perm_const_p (TYPE_MODE (vectype), TYPE_MODE (vectype), indices)) + if (!can_vec_perm_const_p (TYPE_MODE (vectype), + TYPE_MODE (vectype), indices)) continue; + gimple_stmt_iterator gsi_r = gsi_for_stmt (perm); tree new_mask = vect_gen_perm_mask_checked (vectype, indices); + gimple* perm_replacement; + bool has_view_convert = defs[0] != perms[0]; + + if (has_view_convert) + { + tree new_perm_lhs + = make_ssa_name (TREE_TYPE (gimple_assign_lhs (perms[0]))); + + gimple* new_perm + = gimple_build_assign (new_perm_lhs, VEC_PERM_EXPR, + gimple_assign_rhs1 (perms[0]), + gimple_assign_rhs2 (perms[0]), + new_mask); + + gsi_insert_before (&gsi_r, new_perm, GSI_SAME_STMT); + + perm_replacement + = gimple_build_assign (gimple_assign_lhs (perm), + VIEW_CONVERT_EXPR, + build1 (VIEW_CONVERT_EXPR, + vectype, new_perm_lhs)); + } + else + perm_replacement + = gimple_build_assign (gimple_assign_lhs (perm), VEC_PERM_EXPR, + gimple_assign_rhs1 (perms[0]), + gimple_assign_rhs2 (perms[0]), + new_mask); + + /* temporary solution for not re-processing these statements. */ gimple_assign_set_rhs1 (perm, gimple_assign_rhs1 (perms[0])); gimple_assign_set_rhs2 (perm, gimple_assign_rhs2 (perms[0])); - gimple_assign_set_rhs3 (perm, new_mask); - update_stmt (perm); - if (dump_file) { - fprintf(dump_file, " New "); print_gimple_stmt(dump_file, perm, 0); - } + gsi_replace (&gsi_r, perm_replacement, false); } } }