From 650a8fcf8cabb103e1e1cbd40711f1decbb09d5e Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 6 Dec 2017 09:16:44 +0100 Subject: [PATCH] re PR tree-optimization/81945 (ICE in operator[], at vec.h:749) PR tree-optimization/81945 * cfgloop.h (FOR_EACH_LOOP_FN): Use FN instead of hardcoding fn. * tree-cfg.c (move_sese_region_to_fn): If any of the loops moved to dest_cfun has orig_loop_num set, either remap it to the new loop number if the loop got moved too, or clear it. * gcc.dg/graphite/pr81945.c: New test. From-SVN: r255438 --- gcc/ChangeLog | 8 ++++++++ gcc/cfgloop.h | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/graphite/pr81945.c | 21 +++++++++++++++++++++ gcc/tree-cfg.c | 16 ++++++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/graphite/pr81945.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 603f7f0cf58..b3f5784b1a8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-12-06 Jakub Jelinek + + PR tree-optimization/81945 + * cfgloop.h (FOR_EACH_LOOP_FN): Use FN instead of hardcoding fn. + * tree-cfg.c (move_sese_region_to_fn): If any of the loops moved + to dest_cfun has orig_loop_num set, either remap it to the new + loop number if the loop got moved too, or clear it. + 2017-12-05 Steve Ellcey * config/aarch64/thunderx2-t99.md (thunderx2t99_branch): Add trap diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h index dce01bdd56a..687cdb55c53 100644 --- a/gcc/cfgloop.h +++ b/gcc/cfgloop.h @@ -766,7 +766,7 @@ loop_iterator::~loop_iterator () (LOOP) = li.next ()) #define FOR_EACH_LOOP_FN(FN, LOOP, FLAGS) \ - for (loop_iterator li(fn, &(LOOP), FLAGS); \ + for (loop_iterator li(FN, &(LOOP), FLAGS); \ (LOOP); \ (LOOP) = li.next ()) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 983bcd86b86..1ec2e947a54 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-12-06 Jakub Jelinek + + PR tree-optimization/81945 + * gcc.dg/graphite/pr81945.c: New test. + 2017-12-05 Matthew Gretton-Dann * gcc.c-torture/unsorted/dump-noaddr.x: Generate dump files in diff --git a/gcc/testsuite/gcc.dg/graphite/pr81945.c b/gcc/testsuite/gcc.dg/graphite/pr81945.c new file mode 100644 index 00000000000..0dc66195120 --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/pr81945.c @@ -0,0 +1,21 @@ +/* PR tree-optimization/81945 */ +/* { dg-do compile { target pthread } } */ +/* { dg-options "-O3 -ftree-parallelize-loops=2 -floop-nest-optimize" } */ + +unsigned long int v; + +void +foo (int x, int y, long int *a) +{ + do + { + int **b; + + while (y != 0) + ; + v *= 2; + **b = *a; + ++x; + } + while (x < 1); +} diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 2501a9cb8bb..e313df90443 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -7468,6 +7468,8 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb, loops->state = LOOPS_MAY_HAVE_MULTIPLE_LATCHES; set_loops_for_fn (dest_cfun, loops); + vec *larray = get_loops (saved_cfun)->copy (); + /* Move the outlined loop tree part. */ num_nodes = bbs.length (); FOR_EACH_VEC_ELT (bbs, i, bb) @@ -7514,6 +7516,20 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb, loop->aux = current_loops->tree_root; loop0->aux = current_loops->tree_root; + /* Fix up orig_loop_num. If the block referenced in it has been moved + to dest_cfun, update orig_loop_num field, otherwise clear it. */ + struct loop *dloop; + FOR_EACH_LOOP_FN (dest_cfun, dloop, 0) + if (dloop->orig_loop_num) + { + if ((*larray)[dloop->orig_loop_num] != NULL + && get_loop (saved_cfun, dloop->orig_loop_num) == NULL) + dloop->orig_loop_num = (*larray)[dloop->orig_loop_num]->num; + else + dloop->orig_loop_num = 0; + } + ggc_free (larray); + pop_cfun (); /* Move blocks from BBS into DEST_CFUN. */ -- 2.30.2