2012-08-13 Richard Guenther * cfgloopmanip.c (add_loop): Adjust loop depth of blocks in subloops. * tree-cfg.c (print_loop): Avoid ICEing for loop with multiple latches. * gcc.dg/torture/loop-1.c: New testcase. Index: gcc/cfgloopmanip.c =================================================================== *** gcc/cfgloopmanip.c (revision 190339) --- gcc/cfgloopmanip.c (working copy) *************** add_loop (struct loop *loop, struct loop *** 447,452 **** --- 447,455 ---- flow_loop_tree_node_remove (subloop); flow_loop_tree_node_add (loop, subloop); } + /* We need to adjust loop depth information on basic-blocks that + are part of any subloop. */ + bbs[i]->loop_depth++; } /* Update the information about loop exit edges. */ Index: gcc/tree-cfg.c =================================================================== *** gcc/tree-cfg.c (revision 190339) --- gcc/tree-cfg.c (working copy) *************** print_loop (FILE *file, struct loop *loo *** 6870,6877 **** s_indent[indent] = '\0'; /* Print loop's header. */ ! fprintf (file, "%sloop_%d (header = %d, latch = %d", s_indent, ! loop->num, loop->header->index, loop->latch->index); fprintf (file, ", niter = "); print_generic_expr (file, loop->nb_iterations, 0); --- 6969,6980 ---- s_indent[indent] = '\0'; /* Print loop's header. */ ! fprintf (file, "%sloop_%d (header = %d", s_indent, ! loop->num, loop->header->index); ! if (loop->latch) ! fprintf (file, ", latch = %d", loop->latch->index); ! else ! fprintf (file, ", multiple latches"); fprintf (file, ", niter = "); print_generic_expr (file, loop->nb_iterations, 0); Index: gcc/testsuite/gcc.dg/torture/loop-1.c =================================================================== *** gcc/testsuite/gcc.dg/torture/loop-1.c (revision 0) --- gcc/testsuite/gcc.dg/torture/loop-1.c (working copy) *************** *** 0 **** --- 1,20 ---- + /* { dg-do compile } */ + + void foo (int x, int r) + { + loop4: + if (r >= x) + { + goto loop4_latch; + } + else + { + loop5: + if (r >= x) + goto loop4_latch; + goto loop5; + } + loop4_latch: + goto loop4; + } +