From e0bdccac582c01c928a05f26edcd8f5ac24669eb Mon Sep 17 00:00:00 2001 From: Bin Cheng Date: Wed, 7 Apr 2021 10:24:32 +0800 Subject: [PATCH] tree-optimization/98736 - use programing order preserved RPO in ldist Tree loop distribution uses RPO to build reduced dependence graph, it's important that RPO preserves the original programing order. Though it usually does so, when distributing loop nest, exit BB can be placed before some loop BBs while after loop header. This patch fixes the issue by calling rev_post_order_and_mark_dfs_back_seme. gcc/ChangeLog: PR tree-optimization/98736 * tree-loop-distribution.c * (loop_distribution::bb_top_order_init): Compute RPO with programing order preserved by calling function rev_post_order_and_mark_dfs_back_seme. gcc/testsuite/ChangeLog: PR tree-optimization/98736 * gcc.c-torture/execute/pr98736.c: New test. --- gcc/testsuite/gcc.c-torture/execute/pr98736.c | 14 ++++++++++++++ gcc/tree-loop-distribution.c | 12 ++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr98736.c diff --git a/gcc/testsuite/gcc.c-torture/execute/pr98736.c b/gcc/testsuite/gcc.c-torture/execute/pr98736.c new file mode 100644 index 0000000..c066abc --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr98736.c @@ -0,0 +1,14 @@ +/* PR tree-optimization/98736 */ + +int a[6]; +char b, c; +int main() { + int d[4] = {0, 0, 0, 0}; + for (c = 0; c <= 5; c++) { + for (b = 2; b != 0; b++) + a[c] = 8; + a[c] = d[3]; + } + if (a[0] != 0) + __builtin_abort(); +} diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c index 7ee19fc..583bb06 100644 --- a/gcc/tree-loop-distribution.c +++ b/gcc/tree-loop-distribution.c @@ -3152,11 +3152,19 @@ loop_distribution::distribute_loop (class loop *loop, vec stmts, void loop_distribution::bb_top_order_init (void) { int rpo_num; - int *rpo = XNEWVEC (int, last_basic_block_for_fn (cfun)); + int *rpo = XNEWVEC (int, n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS); + edge entry = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun)); + bitmap exit_bbs = BITMAP_ALLOC (NULL); bb_top_order_index = XNEWVEC (int, last_basic_block_for_fn (cfun)); bb_top_order_index_size = last_basic_block_for_fn (cfun); - rpo_num = pre_and_rev_post_order_compute_fn (cfun, NULL, rpo, true); + + entry->flags &= ~EDGE_DFS_BACK; + bitmap_set_bit (exit_bbs, EXIT_BLOCK); + rpo_num = rev_post_order_and_mark_dfs_back_seme (cfun, entry, exit_bbs, true, + rpo, NULL); + BITMAP_FREE (exit_bbs); + for (int i = 0; i < rpo_num; i++) bb_top_order_index[rpo[i]] = i; -- 2.7.4