+/* Fix placement of LOOP inside loop tree, i.e. find the innermost superloop
+ of LOOP to that leads at least one exit edge of LOOP, and set it
+ as the immediate superloop of LOOP. Return true if the immediate superloop
+ of LOOP changed. */
+
+static bool
+fix_loop_placement (struct loop *loop)
+{
+ unsigned i;
+ edge e;
+ VEC (edge, heap) *exits = get_loop_exit_edges (loop);
+ struct loop *father = current_loops->tree_root, *act;
+ bool ret = false;
+
+ for (i = 0; VEC_iterate (edge, exits, i, e); i++)
+ {
+ act = find_common_loop (loop, e->dest->loop_father);
+ if (flow_loop_nested_p (father, act))
+ father = act;
+ }
+
+ if (father != loop_outer (loop))
+ {
+ for (act = loop_outer (loop); act != father; act = loop_outer (act))
+ act->num_nodes -= loop->num_nodes;
+ flow_loop_tree_node_remove (loop);
+ flow_loop_tree_node_add (father, loop);
+
+ /* The exit edges of LOOP no longer exits its original immediate
+ superloops; remove them from the appropriate exit lists. */
+ for (i = 0; VEC_iterate (edge, exits, i, e); i++)
+ rescan_loop_exit (e, false, false);
+
+ ret = true;
+ }
+
+ VEC_free (edge, heap, exits);
+ return ret;
+}
+