http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54838
--- Comment #15 from Marek Polacek <mpolacek at gcc dot gnu.org> 2012-12-14 16:12:48 UTC --- The issue here is that we have a loop with header and two latches, and via delete_basic_block we delete both latches (and all edges of those two latches). So, we don't have a loop anymore, but the header has still loop_depth > 0, merge_latch_edges of course ICEs on it, because there's an assert: gcc_assert (latches.length () > 0); but the latches are already gone. I think that in this case we want to just set the loop->header to NULL (or cancel_loop_tree, or unloop, or...). What I have in mind is basically something like: --- a/gcc/cfghooks.c +++ b/gcc/cfghooks.c @@ -552,6 +552,23 @@ delete_basic_block (basic_block bb) loops_state_set (LOOPS_NEED_FIXUP); } + if (loop->header + && bb->loop_father != current_loops->tree_root) + { + edge_iterator ei; + edge e; + unsigned n_back_edges = 0; + + FOR_EACH_EDGE (e, ei, loop->header->preds) + if (e->flags & EDGE_DFS_BACK) + n_back_edges++; + + if (n_back_edges == 0) + { + loop->header = NULL; + loops_state_set (LOOPS_NEED_FIXUP); + } + } remove_bb_from_loops (bb); } this fixes this ICE, but causes other ICEs. I'd be really really grateful for any hints.