http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60518
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- Ok, so it's branch_prob()s call of split_block that splits the common latch of loops 1 and 2 <bb 3>: (header loop 1) <bb 4>: (header loop 2, latch loop 2 and 1) _2 = fn1 (); if (_2 != 0) goto <bb 4>; else goto <bb 3>; the cfghook adjusts the latch of loop 2 properly (bb4s loop father is 2) but fails to notice that bb4 is also the latch of loop 1 ... so this CFG hook loop handling only handles this correctly if we have simple latches (because there the latch always belongs to its loop). Fix: Index: gcc/cfghooks.c =================================================================== --- gcc/cfghooks.c (revision 208536) +++ gcc/cfghooks.c (working copy) @@ -510,9 +510,13 @@ split_block (basic_block bb, void *i) if (current_loops != NULL) { + edge_iterator ei; + edge e; add_bb_to_loop (new_bb, bb->loop_father); - if (bb->loop_father->latch == bb) - bb->loop_father->latch = new_bb; + /* Identify all loops bb may have been the latch of and adjust them. */ + FOR_EACH_EDGE (e, ei, new_bb->succs) + if (e->dest->loop_father->latch == bb) + e->dest->loop_father->latch = new_bb; } res = make_single_succ_edge (bb, new_bb, EDGE_FALLTHRU);