+ if (num != 0)
+ {
+ basic_block *tos, *worklist;
+
+ /* When called recursively, first do a quick discovery
+ of reachable bbs after the above changes and only
+ consider conditions in still reachable bbs. */
+ tos = worklist = XNEWVEC (basic_block, loop->num_nodes);
+
+ for (i = 0; i < loop->num_nodes; i++)
+ bbs[i]->flags &= ~BB_REACHABLE;
+
+ /* Start with marking header. */
+ *tos++ = bbs[0];
+ bbs[0]->flags |= BB_REACHABLE;
+
+ /* Iterate: find everything reachable from what we've already seen
+ within the same innermost loop. Don't look through false edges
+ if condition is always true or true edges if condition is
+ always false. */
+ while (tos != worklist)
+ {
+ basic_block b = *--tos;
+ edge e;
+ edge_iterator ei;
+ int flags = 0;
+
+ if (EDGE_COUNT (b->succs) == 2)
+ {
+ gimple stmt = last_stmt (b);
+ if (stmt
+ && gimple_code (stmt) == GIMPLE_COND)
+ {
+ if (gimple_cond_true_p (stmt))
+ flags = EDGE_FALSE_VALUE;
+ else if (gimple_cond_false_p (stmt))
+ flags = EDGE_TRUE_VALUE;
+ }
+ }
+
+ FOR_EACH_EDGE (e, ei, b->succs)
+ {
+ basic_block dest = e->dest;
+
+ if (dest->loop_father == loop
+ && !(dest->flags & BB_REACHABLE)
+ && !(e->flags & flags))
+ {
+ *tos++ = dest;
+ dest->flags |= BB_REACHABLE;
+ }
+ }
+ }
+
+ free (worklist);
+
+ /* Find a bb to unswitch on. */
+ for (; found < loop->num_nodes; found++)
+ if ((bbs[found]->flags & BB_REACHABLE)
+ && (cond = tree_may_unswitch_on (bbs[found], loop)))
+ break;
+
+ if (found == loop->num_nodes)
+ {
+ free (bbs);
+ return changed;
+ }
+ }
+