From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1923) id 772273858C66; Tue, 23 Jan 2024 20:58:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 772273858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706043498; bh=EuGG3CkQYMvu0Mebcx/t2I/owgNWpkZKJfWspxJLa64=; h=From:To:Subject:Date:From; b=IwCDbn8JtsRLrPIh/GdKZ8MHGvOmt1KKF/QVSoESXv/Z0RlwVriclJMvKHt9nE5yq cMnZc9OGRwA+JZo5BYBqPTqe7JZuUybB1w8E5+SVtKeT8HhJs+Bpmn+r1CU1J9BuKz SwnPkSHFC7A2v3H14Dap2sbAyTyhsaVQMaL8dQR4= 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: ad485760c6088fb57e3f31e29beaa207bfd9993d X-Git-Newrev: 636cdb17256940e2de18810a8e47e7deafa172ff Message-Id: <20240123205818.772273858C66@sourceware.org> Date: Tue, 23 Jan 2024 20:58:18 +0000 (GMT) List-Id: https://gcc.gnu.org/g:636cdb17256940e2de18810a8e47e7deafa172ff commit 636cdb17256940e2de18810a8e47e7deafa172ff 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 4f4cb38f185..724e53a4cfd 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -8246,18 +8246,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); @@ -8293,8 +8293,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; @@ -8314,6 +8314,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); @@ -8329,18 +8330,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); @@ -8437,6 +8441,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); } }