+static bool
+sel_bb_empty_or_nop_p (basic_block bb)
+{
+ insn_t first = sel_bb_head (bb), last;
+
+ if (first == NULL_RTX)
+ return true;
+
+ if (!INSN_NOP_P (first))
+ return false;
+
+ if (bb == EXIT_BLOCK_PTR)
+ return false;
+
+ last = sel_bb_end (bb);
+ if (first != last)
+ return false;
+
+ return true;
+}
+
+/* Collect all loop exits recursively, skipping empty BBs between them.