From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 9E8BD3858284; Wed, 13 Sep 2023 11:42:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E8BD3858284 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694605330; bh=/cV9IvyTKGhLF5zoThL8u0JoXqiI5QlFBelWtwGoQjU=; h=From:To:Subject:Date:From; b=EzjI5lordlhHH1QT8p34QDHHi2DR9r34iix/WwJZ69qS96GujwI90eJgM9tMQJz7g uH9QMORo+PRGJEpM5YHafnj9732Scua4s6cjCtbBszSYDb0YCSpwIumJZzViidur+d D+OrYsyBhFBfDZ6FoH7QbI5zW8jHQJ6xNrjWEEc0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-3920] tree-optimization/111387 - BB SLP and irreducible regions X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: c0a70df6403397a69204cba1df82114a9ddf7076 X-Git-Newrev: 04238615bba435f0b0ca7b263ad2c6bdb596e865 Message-Id: <20230913114210.9E8BD3858284@sourceware.org> Date: Wed, 13 Sep 2023 11:42:10 +0000 (GMT) List-Id: https://gcc.gnu.org/g:04238615bba435f0b0ca7b263ad2c6bdb596e865 commit r14-3920-g04238615bba435f0b0ca7b263ad2c6bdb596e865 Author: Richard Biener Date: Wed Sep 13 11:04:31 2023 +0200 tree-optimization/111387 - BB SLP and irreducible regions When we split an irreducible region for BB vectorization analysis the defensive handling of external backedge defs in vect_get_and_check_slp_defs doesn't work since that relies on dominance info to identify a backedge. The testcase also shows we are iterating over the function in a sub-optimal way which is why we split the irreducible region in the first place. The fix is to mark backedges and use EDGE_DFS_BACK to identify them and to use the region RPO compute which can produce a RPO order keeping cycles in a better order (and as side effect marks backedges). PR tree-optimization/111387 * tree-vect-slp.cc (vect_get_and_check_slp_defs): Check EDGE_DFS_BACK when doing BB vectorization. (vect_slp_function): Use rev_post_order_and_mark_dfs_back_seme to compute RPO and mark backedges. * gcc.dg/torture/pr111387.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/torture/pr111387.c | 34 +++++++++++++++++++++++++++++++++ gcc/tree-vect-slp.cc | 16 ++++++++++++---- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr111387.c b/gcc/testsuite/gcc.dg/torture/pr111387.c new file mode 100644 index 000000000000..e14eeef6e4ad --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr111387.c @@ -0,0 +1,34 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-ftree-vectorize -fno-vect-cost-model" } */ + +struct { + unsigned a; + unsigned b; +} c; +int d, e, f, g, h; +int main() +{ + if (c.b && g && g > 7) + goto i; + j: + if (c.a) { + int k = 0; + unsigned l = c.b; + if (0) { + m: + k = l = c.b; + } + c.a = k; + c.b = l; + } + if (0) { + i: + goto m; + } + if (d) + goto j; + for (f = 5; f; f--) + if (h) + e = 0; + return 0; +} diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 0cf6e02285e9..a3e54ebf62a2 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -628,9 +628,13 @@ vect_get_and_check_slp_defs (vec_info *vinfo, unsigned char swap, { oprnd = gimple_arg (stmt_info->stmt, opno); if (gphi *stmt = dyn_cast (stmt_info->stmt)) - backedge = dominated_by_p (CDI_DOMINATORS, - gimple_phi_arg_edge (stmt, opno)->src, - gimple_bb (stmt_info->stmt)); + { + edge e = gimple_phi_arg_edge (stmt, opno); + backedge = (is_a (vinfo) + ? e->flags & EDGE_DFS_BACK + : dominated_by_p (CDI_DOMINATORS, e->src, + gimple_bb (stmt_info->stmt))); + } } if (TREE_CODE (oprnd) == VIEW_CONVERT_EXPR) oprnd = TREE_OPERAND (oprnd, 0); @@ -7771,7 +7775,11 @@ vect_slp_function (function *fun) { bool r = false; int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (fun)); - unsigned n = pre_and_rev_post_order_compute_fn (fun, NULL, rpo, false); + auto_bitmap exit_bbs; + bitmap_set_bit (exit_bbs, EXIT_BLOCK); + edge entry = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (fun)); + unsigned n = rev_post_order_and_mark_dfs_back_seme (fun, entry, exit_bbs, + true, rpo, NULL); /* For the moment split the function into pieces to avoid making the iteration on the vector mode moot. Split at points we know