https://gcc.gnu.org/g:1d25e357c047f48cee50df318e965a0fbf84e2fe
commit r15-7098-g1d25e357c047f48cee50df318e965a0fbf84e2fe Author: Richard Biener <rguent...@suse.de> Date: Tue Jan 21 09:45:41 2025 +0100 tree-optimization/118569 - LC SSA broken after unrolling The following amends the previous fix to mark all of the loop BBs as need to be scanned for new LC PHI uses when its nesting parents changed, noticing one caller of fix_loop_placement was already doing that. So the following moves this code into fix_loop_placement, covering both callers now. PR tree-optimization/118569 * cfgloopmanip.cc (fix_loop_placement): When the loops nesting parents changed, mark all blocks to be scanned for LC PHI uses. (fix_bb_placements): Remove code moved into fix_loop_placement. * gcc.dg/torture/pr118569.c: New testcase. Diff: --- gcc/cfgloopmanip.cc | 22 ++++++++++---------- gcc/testsuite/gcc.dg/torture/pr118569.c | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/gcc/cfgloopmanip.cc b/gcc/cfgloopmanip.cc index 573146b2e284..2c28437b34d9 100644 --- a/gcc/cfgloopmanip.cc +++ b/gcc/cfgloopmanip.cc @@ -154,10 +154,17 @@ fix_loop_placement (class loop *loop, bool *irred_invalidated, if (e->flags & EDGE_IRREDUCIBLE_LOOP) *irred_invalidated = true; rescan_loop_exit (e, false, false); - /* Any LC SSA PHIs on e->dest might now be on the wrong edge - if their defs were in a former outer loop. */ - if (loop_closed_ssa_invalidated) - bitmap_set_bit (loop_closed_ssa_invalidated, e->src->index); + } + /* Any LC SSA PHIs on e->dest might now be on the wrong edge + if their defs were in a former outer loop. Also all uses + in the original inner loop of defs in the outer loop(s) now + require LC PHI nodes. */ + if (loop_closed_ssa_invalidated) + { + basic_block *bbs = get_loop_body (loop); + for (unsigned i = 0; i < loop->num_nodes; ++i) + bitmap_set_bit (loop_closed_ssa_invalidated, bbs[i]->index); + free (bbs); } ret = true; @@ -233,13 +240,6 @@ fix_bb_placements (basic_block from, loop_closed_ssa_invalidated)) continue; target_loop = loop_outer (from->loop_father); - if (loop_closed_ssa_invalidated) - { - basic_block *bbs = get_loop_body (from->loop_father); - for (unsigned i = 0; i < from->loop_father->num_nodes; ++i) - bitmap_set_bit (loop_closed_ssa_invalidated, bbs[i]->index); - free (bbs); - } } else { diff --git a/gcc/testsuite/gcc.dg/torture/pr118569.c b/gcc/testsuite/gcc.dg/torture/pr118569.c new file mode 100644 index 000000000000..c5b404aded53 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr118569.c @@ -0,0 +1,36 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fno-tree-ch -fno-tree-ccp -fno-tree-fre" } */ + +volatile int a; +int b, c, d, e, f, g; +int main() { + int i = 2, j = 1; +k: + if (!e) + ; + else { + short l = 1; + if (0) + m: + d = g; + f = 0; + for (; f < 2; f++) { + if (f) + for (; j < 2; j++) + if (i) + goto m; + a; + if (l) + continue; + i = 0; + while (c) + l++; + } + g = 0; + } + if (b) { + i = 1; + goto k; + } + return 0; +}