From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1923) id 6D2323882050; Tue, 28 Nov 2023 13:35:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D2323882050 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701178515; bh=ETo4RM+W6KXBS2yERU8MFkG83QQ5HxeEM8bIP2nvQcY=; h=From:To:Subject:Date:From; b=jsJmCnY0EqhVH9bZyciRQkd54yMQeSmYvV0dh9Vt+e3cROzyorfBQ9Kd5boWVEVDJ i/LfIQReoUWxgeFLYsZWdoWp1mhr1DD33YmIsaAwBbNxsk1GxL6+jeoUEV9duhqVZ4 yB625K06JIS5NdCj6xGCxppV2apEaoIjJne42x2A= 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)] tree-optimization: use fewer lanes on VEC_PERM_EXPR for two operators X-Act-Checkin: gcc X-Git-Author: Manolis Tsamis X-Git-Refname: refs/vendors/vrull/heads/slp-improvements X-Git-Oldrev: 527c082ecad2383d022857e5b50d3fba8705cbe6 X-Git-Newrev: bea3dc1e4af4fe1d9aa34e9122321a9e43896512 Message-Id: <20231128133515.6D2323882050@sourceware.org> Date: Tue, 28 Nov 2023 13:35:15 +0000 (GMT) List-Id: https://gcc.gnu.org/g:bea3dc1e4af4fe1d9aa34e9122321a9e43896512 commit bea3dc1e4af4fe1d9aa34e9122321a9e43896512 Author: Manolis Tsamis Date: Fri Nov 17 17:42:30 2023 +0100 tree-optimization: use fewer lanes on VEC_PERM_EXPR for two operators Currently when SLP nodes are built with "two_operators == true" the VEC_PERM_EXPR that merges the result selects a lane only based on the operator found. In the case that the input nodes have duplicate elements there may be more than one ways to chose. This commit OBtries to use an existing lane if possible, which can free up lanes that can be used in other optimizations. For example, given two vectors with duplicates: A = {a1, a1, a2, a2} B = {b1, b1, b2, b2} a two_operator node with operators +, -, +, - can be built as: RES = VEC_PERM_EXPR(0, 4, 2, 6) and use 2 lanes with this commit. The existing implementation would have built a (0, 5, 2, 7) permutation and have used 4 lanes. This commit adds a case that if the current element can be found in another lane that has been used previously then that lane will be reused. This can happen when the ONE and TWO contain duplicate elements and reduces the number of 'active' lanes. Diff: --- gcc/tree-vect-slp.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 681f72c43fe..489e3f9ee12 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -2848,7 +2848,25 @@ fail: gassign *ostmt = as_a (ostmt_info->stmt); if (gimple_assign_rhs_code (ostmt) != code0) { - SLP_TREE_LANE_PERMUTATION (node).safe_push (std::make_pair (1, i)); + /* If the current element can be found in another lane that has + been used previously then use that one instead. This can + happen when the ONE and TWO contain duplicate elements and + reduces the number of 'active' lanes. */ + int idx = i; + for (int alt_idx = (int) i - 1; alt_idx >= 0; alt_idx--) + { + gassign *alt_stmt = as_a (stmts[alt_idx]->stmt); + if (gimple_assign_rhs_code (alt_stmt) == code0 + && gimple_assign_rhs1 (ostmt) + == gimple_assign_rhs1 (alt_stmt) + && gimple_assign_rhs2 (ostmt) + == gimple_assign_rhs2 (alt_stmt)) + { + idx = alt_idx; + break; + } + } + SLP_TREE_LANE_PERMUTATION (node).safe_push (std::make_pair (1, idx)); ocode = gimple_assign_rhs_code (ostmt); j = i; }