From 7ba6738bd24dacf4f207ddc7142dde603ddc7482 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 5 Dec 2018 12:05:59 +0100 Subject: [PATCH] re PR tree-optimization/87360 (ICE in remove_redundant_iv_tests at gcc/tree-ssa-loop-ivcanon.c:571 since r255467) PR tree-optimization/87360 * gimple-loop-jam.c (tree_loop_unroll_and_jam): On failure to analyze data dependencies, don't return false, just continue. Formatting fixes. (merge_loop_tree, bb_prevents_fusion_p, unroll_jam_possible_p, fuse_loops): Formatting fixes. * g++.dg/opt/pr87360.C: New test. * gfortran.dg/pr87360.f90: New test. From-SVN: r266820 --- gcc/ChangeLog | 7 +++++++ gcc/gimple-loop-jam.c | 18 +++++++++--------- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/opt/pr87360.C | 27 +++++++++++++++++++++++++++ gcc/testsuite/gfortran.dg/pr87360.f90 | 5 +++++ 5 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/opt/pr87360.C create mode 100644 gcc/testsuite/gfortran.dg/pr87360.f90 diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 22ca348..a119bb3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,12 @@ 2018-12-05 Jakub Jelinek + PR tree-optimization/87360 + * gimple-loop-jam.c (tree_loop_unroll_and_jam): On failure to analyze + data dependencies, don't return false, just continue. Formatting + fixes. + (merge_loop_tree, bb_prevents_fusion_p, unroll_jam_possible_p, + fuse_loops): Formatting fixes. + PR sanitizer/88333 * cfgexpand.c (expand_stack_vars): If asan_vec is empty, start with aligning frame offset to ASAN_RED_ZONE_SIZE bytes. diff --git a/gcc/gimple-loop-jam.c b/gcc/gimple-loop-jam.c index c6bd042..5920cad 100644 --- a/gcc/gimple-loop-jam.c +++ b/gcc/gimple-loop-jam.c @@ -118,7 +118,7 @@ merge_loop_tree (struct loop *loop, struct loop *old) for (i = 0; i < n; i++) { /* If the block was direct child of OLD loop it's now part - of LOOP. If it was outside OLD, then it moved into LOOP + of LOOP. If it was outside OLD, then it moved into LOOP as well. This avoids changing the loop father for BBs in inner loops of OLD. */ if (bbs[i]->loop_father == old @@ -167,7 +167,7 @@ bb_prevents_fusion_p (basic_block bb) * stores or unknown side-effects prevent fusion * loads don't * computations into SSA names: these aren't problematic. Their - result will be unused on the exit edges of the first N-1 copies + result will be unused on the exit edges of the first N-1 copies (those aren't taken after unrolling). If they are used on the other edge (the one leading to the outer latch block) they are loop-carried (on the outer loop) and the Nth copy of BB will @@ -282,12 +282,12 @@ unroll_jam_possible_p (struct loop *outer, struct loop *loop) if (!simple_iv (loop, loop, op, &iv, true)) return false; /* The inductions must be regular, loop invariant step and initial - value. */ + value. */ if (!expr_invariant_in_loop_p (outer, iv.step) || !expr_invariant_in_loop_p (outer, iv.base)) return false; /* XXX With more effort we could also be able to deal with inductions - where the initial value is loop variant but a simple IV in the + where the initial value is loop variant but a simple IV in the outer loop. The initial value for the second body would be the original initial value plus iv.base.step. The next value for the fused loop would be the original next value of the first @@ -322,7 +322,7 @@ fuse_loops (struct loop *loop) gcc_assert (EDGE_COUNT (next->header->preds) == 1); /* The PHI nodes of the second body (single-argument now) - need adjustments to use the right values: either directly + need adjustments to use the right values: either directly the value of the corresponding PHI in the first copy or the one leaving the first body which unrolling did for us. @@ -449,13 +449,13 @@ tree_loop_unroll_and_jam (void) dependences.create (10); datarefs.create (10); if (!compute_data_dependences_for_loop (outer, true, &loop_nest, - &datarefs, &dependences)) + &datarefs, &dependences)) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, "Cannot analyze data dependencies\n"); free_data_refs (datarefs); free_dependence_relations (dependences); - return false; + continue; } if (!datarefs.length ()) continue; @@ -490,7 +490,7 @@ tree_loop_unroll_and_jam (void) &removed)) { /* Couldn't get the distance vector. For two reads that's - harmless (we assume we should unroll). For at least + harmless (we assume we should unroll). For at least one write this means we can't check the dependence direction and hence can't determine safety. */ @@ -503,7 +503,7 @@ tree_loop_unroll_and_jam (void) } /* We regard a user-specified minimum percentage of zero as a request - to ignore all profitability concerns and apply the transformation + to ignore all profitability concerns and apply the transformation always. */ if (!PARAM_VALUE (PARAM_UNROLL_JAM_MIN_PERCENT)) profit_unroll = 2; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index abc2d2f..5cabb68 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2018-12-05 Jakub Jelinek + PR tree-optimization/87360 + * g++.dg/opt/pr87360.C: New test. + * gfortran.dg/pr87360.f90: New test. + PR c++/87897 * g++.dg/init/const13.C: New test. diff --git a/gcc/testsuite/g++.dg/opt/pr87360.C b/gcc/testsuite/g++.dg/opt/pr87360.C new file mode 100644 index 0000000..f54bc61 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr87360.C @@ -0,0 +1,27 @@ +// PR tree-optimization/87360 +// { dg-do compile { target size32plus } } +// { dg-options "-O3 -fno-tree-dce --param unroll-jam-min-percent=0" } + +void abort (void); + +void foo (int N) +{ + int i, j; + int x[1000][1000]; + + for (i = 0; i < N; i++) + for (j = 0; j < N; j++) + x[i][j] = i + j + 3; + + for (i = 0; i < N; i++) + for (j = 0; j < N; j++) + if (x[i][j] != i + j + 3) + abort (); +} + +int main(void) +{ + foo (1000); + + return 0; +} diff --git a/gcc/testsuite/gfortran.dg/pr87360.f90 b/gcc/testsuite/gfortran.dg/pr87360.f90 new file mode 100644 index 0000000..8432534 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr87360.f90 @@ -0,0 +1,5 @@ +! PR tree-optimization/87360 +! { dg-do compile } +! { dg-options "-fno-tree-dce -O3 --param max-completely-peeled-insns=0" } + +include 'function_optimize_2.f90' -- 2.7.4