From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 5609C385800E; Mon, 20 Nov 2023 14:01:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5609C385800E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700488911; bh=B53Y4IwnbJ33WpkImiJuu2df0grhe4V4iLBHvOcl4aM=; h=From:To:Subject:Date:From; b=C532knQPjKSuBWTVJUcc2w9woyFjtQNAveVTK9SGR1XIFr2fQO/P9HK8VAEyrbqNE b+qeqxfXrMWjOkzYoMeXijr6hlkhKo4BR3GtmpYMzTG5TR3LjccFNp6+fIdtgFdApA vZRAQ9R2txJZzvJRUqZXjt1iYXNnMIHs3f2tnLCw= 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-5626] tree-optimization/112281 - loop distribution and zero dependence distances X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: b7a1b89e60c4b492f85b47e02c12b01dd8a6e28b X-Git-Newrev: 3b34902417259031823bff7f853f615a60464bbd Message-Id: <20231120140151.5609C385800E@sourceware.org> Date: Mon, 20 Nov 2023 14:01:51 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3b34902417259031823bff7f853f615a60464bbd commit r14-5626-g3b34902417259031823bff7f853f615a60464bbd Author: Richard Biener Date: Mon Nov 20 13:39:52 2023 +0100 tree-optimization/112281 - loop distribution and zero dependence distances The following fixes an omission in dependence testing for loop distribution. When the overall dependence distance is not zero but the dependence direction in the innermost common loop is = there is a conflict between the partitions and we have to merge them. PR tree-optimization/112281 * tree-loop-distribution.cc (loop_distribution::pg_add_dependence_edges): For = in the innermost common loop record a partition conflict. * gcc.dg/torture/pr112281-1.c: New testcase. * gcc.dg/torture/pr112281-2.c: Likewise. Diff: --- gcc/testsuite/gcc.dg/torture/pr112281-1.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/torture/pr112281-2.c | 18 ++++++++++++++++++ gcc/tree-loop-distribution.cc | 18 ++++++++++++++---- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr112281-1.c b/gcc/testsuite/gcc.dg/torture/pr112281-1.c new file mode 100644 index 00000000000..711f5663195 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr112281-1.c @@ -0,0 +1,18 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-loop-distribution" } */ + +struct { + int : 8; + int a; +} b, d[4] = {{0}, {0}, {0}, {5}}; +int c, e; +int main() { + for (c = 2; c; c--) + for (e = 0; e < 2; e++) { + d[c] = b = d[c + 1]; + d[c + 1].a = 0; + } + if (b.a != 0) + __builtin_abort(); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr112281-2.c b/gcc/testsuite/gcc.dg/torture/pr112281-2.c new file mode 100644 index 00000000000..d7671e3322b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr112281-2.c @@ -0,0 +1,18 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-loop-distribution" } */ + +struct { + int : 8; + int a; +} b, d[4] = {{5}, {0}, {0}, {0}}; +int c, e; +int main() { + for (c = 0; c < 2; c++) + for (e = 0; e < 2; e++) { + d[c + 1] = b = d[c]; + d[c].a = 0; + } + if (b.a != 0) + __builtin_abort(); + return 0; +} diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc index ffca535064b..95c1eea65be 100644 --- a/gcc/tree-loop-distribution.cc +++ b/gcc/tree-loop-distribution.cc @@ -2155,9 +2155,6 @@ loop_distribution::pg_add_dependence_edges (struct graph *rdg, int dir, } else if (DDR_ARE_DEPENDENT (ddr) == NULL_TREE) { - if (DDR_REVERSED_P (ddr)) - this_dir = -this_dir; - /* Known dependences can still be unordered througout the iteration space, see gcc.dg/tree-ssa/ldist-16.c and gcc.dg/tree-ssa/pr94969.c. */ @@ -2170,7 +2167,20 @@ loop_distribution::pg_add_dependence_edges (struct graph *rdg, int dir, /* Else as the distance vector is lexicographic positive swap the dependence direction. */ else - this_dir = -this_dir; + { + if (DDR_REVERSED_P (ddr)) + this_dir = -this_dir; + this_dir = -this_dir; + + /* When then dependence distance of the innermost common + loop of the DRs is zero we have a conflict. */ + auto l1 = gimple_bb (DR_STMT (dr1))->loop_father; + auto l2 = gimple_bb (DR_STMT (dr2))->loop_father; + int idx = index_in_loop_nest (find_common_loop (l1, l2)->num, + DDR_LOOP_NEST (ddr)); + if (DDR_DIST_VECT (ddr, 0)[idx] == 0) + this_dir = 2; + } } else this_dir = 0;