From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1923) id D60833858C62; Wed, 17 Jan 2024 19:15:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D60833858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705518901; bh=VCuRhIcDfqkQQIGbKnfcQpmIctmU7ET7zvweOyNywXI=; h=From:To:Subject:Date:From; b=omcS6HKRQ+EAJRhz3pKQWCpXzXinKJ2AQbl88TMHf0fWFWYZXvON3+C3sjCy2ZcvL FX/i7vtNGpIYdOp2/YnunYaHP5t/9R8ezUJVPkXO3JH2Zx2epHm28xlHSaMRd3DjIE 35mOJ8YmKt0eI+oLpaNtIyo7TlxGbMm/H+3S5PTI= 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)] Fix statement ordering for vect_slp_optimize_permutes (#346) X-Act-Checkin: gcc X-Git-Author: Manolis Tsamis X-Git-Refname: refs/vendors/vrull/heads/slp-improvements X-Git-Oldrev: 5c262464666155ff596dd9cb081fa18062164320 X-Git-Newrev: d670ca49c4bb9c894d94de876d592aff34812229 Message-Id: <20240117191501.D60833858C62@sourceware.org> Date: Wed, 17 Jan 2024 19:15:01 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d670ca49c4bb9c894d94de876d592aff34812229 commit d670ca49c4bb9c894d94de876d592aff34812229 Author: Manolis Tsamis Date: Fri Dec 1 12:33:51 2023 +0100 Fix statement ordering for vect_slp_optimize_permutes (#346) There were cases where the code in vect_slp_optimize_permutes would create dependancies to future statements like in this case: c1_7 = VEC_PERM_EXPR <_1, _3, { 0, 1, 4, 5 }>; # VUSE <.MEM_5(D)> _2 = MEM[(veciD.4395 *)a_6(D) + 16B]; c2_8 = VEC_PERM_EXPR <_2, _4, { 2, 3, 6, 7 }>; # VUSE <.MEM_5(D)> _3 = MEM[(veciD.4395 *)a_6(D) + 32B]; # VUSE <.MEM_5(D)> _4 = MEM[(veciD.4395 *)a_6(D) + 48B]; This happened because we modify gimple arguments in-place without guaranteeing anything about their initial order. Since we know the uses of the statements we alter, we can freely reaarange them so the resulting gimple code is correct. Diff: --- gcc/tree-vect-slp.cc | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 30ac656a0af..8f2993b84f1 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -8117,18 +8117,18 @@ get_tree_def (tree name, bool single_use_only) src1_perm = VEC_PERM_EXPR src2_perm = VEC_PERM_EXPR - bop_1 = src1_perm BINOP1 src2_perm - bop_2 = src1_perm BINOP2 src2_perm - STMT = VEC_PERM_EXPR + bop1 = src1_perm BINOP1 src2_perm + bop2 = src1_perm BINOP2 src2_perm + STMT = VEC_PERM_EXPR - and src1_perm, src2_perm, bop_1, bop_2 are not used outside of STMT. + and src1_perm, src2_perm, bop1, bop2 are not used outside of STMT. Return the first two permute statements and the binops through the corresponding pointer arguments. */ static bool -recognise_perm_binop_perm_pattern (gassign *stmt, enum tree_code *binop1, - enum tree_code *binop2, gassign **perm1_out, - gassign **perm2_out) +recognise_perm_binop_perm_pattern (gassign *stmt, + gassign **bop1_out, gassign **bop2_out, + gassign **perm1_out, gassign **perm2_out) { enum tree_code code = gimple_assign_rhs_code (stmt); @@ -8164,8 +8164,8 @@ recognise_perm_binop_perm_pattern (gassign *stmt, enum tree_code *binop1, || !VECTOR_CST_NELTS (gimple_assign_rhs3 (perm2)).is_constant ()) return false; - *binop1 = gimple_assign_rhs_code (bop1); - *binop2 = gimple_assign_rhs_code (bop2); + *bop1_out = bop1; + *bop2_out = bop2; *perm1_out = perm1; *perm2_out = perm2; @@ -8185,6 +8185,7 @@ vect_slp_optimize_permutes (function *fun) FOR_EACH_BB_FN (bb, fun) for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);) { + gimple_stmt_iterator gsi_stmt1 = gsi; gassign *stmt1 = dyn_cast (gsi_stmt (gsi)); gsi_next (&gsi); @@ -8200,18 +8201,21 @@ vect_slp_optimize_permutes (function *fun) vector and merge two of them into one. This case can arise from TWO_OPERATOR SLP patterns because the final permute uses only half of each input vector. */ - enum tree_code binop1_1, binop1_2, binop2_1, binop2_2; + gassign *bop1_1, *bop1_2, *bop2_1, *bop2_2; gassign *src1_1, *src1_2, *src2_1, *src2_2; - if (!recognise_perm_binop_perm_pattern(stmt1, &binop1_1, &binop1_2, + if (!recognise_perm_binop_perm_pattern(stmt1, &bop1_1, &bop1_2, &src1_1, &src1_2)) continue; - if (!recognise_perm_binop_perm_pattern(stmt2, &binop2_1, &binop2_2, + if (!recognise_perm_binop_perm_pattern(stmt2, &bop2_1, &bop2_2, &src2_1, &src2_2)) continue; - if (binop1_1 != binop2_1 || binop1_2 != binop2_2) + if (gimple_assign_rhs_code (bop1_1) != gimple_assign_rhs_code (bop2_1)) + continue; + + if (gimple_assign_rhs_code (bop1_2) != gimple_assign_rhs_code (bop2_2)) continue; tree mask1 = gimple_assign_rhs3 (stmt1); @@ -8308,6 +8312,24 @@ vect_slp_optimize_permutes (function *fun) update_stmt (stmt2); update_stmt (src1_1); update_stmt (src1_2); + + /* We need to move the updated statements because otherwise they may + come before some variable that they depend on. Since we know that + they don't have uses outside the pattern, we can remove them and + add them back in order. */ + gimple_stmt_iterator gsi_rm = gsi_for_stmt (bop1_1); + gsi_remove (&gsi_rm, false); + gsi_rm = gsi_for_stmt (bop1_2); + gsi_remove (&gsi_rm, false); + gsi_rm = gsi_for_stmt (src1_1); + gsi_remove (&gsi_rm, false); + gsi_rm = gsi_for_stmt (src1_2); + gsi_remove (&gsi_rm, false); + + gsi_insert_before (&gsi_stmt1, src1_1, GSI_SAME_STMT); + gsi_insert_before (&gsi_stmt1, src1_2, GSI_SAME_STMT); + gsi_insert_before (&gsi_stmt1, bop1_1, GSI_SAME_STMT); + gsi_insert_before (&gsi_stmt1, bop1_2, GSI_SAME_STMT); } }