- ir_if *last_if = last_ir->as_if();
- if (last_if) {
- bool continue_from_then_branch;
-
- /* Determine which if-statement branch, if any, ends with a break.
- * The branch that did *not* have the break will get a temporary
- * continue inserted in each iteration of the loop unroll.
- *
- * Note that since ls->num_loop_jumps is <= 1, it is impossible for
- * both branches to end with a break.
- */
- ir_instruction *last =
- (ir_instruction *) last_if->then_instructions.get_tail();
-
- if (last && last->ir_type == ir_type_loop_jump
- && ((ir_loop_jump*) last)->is_break()) {
- continue_from_then_branch = false;
- } else {
- last = (ir_instruction *) last_if->then_instructions.get_tail();
-
- if (last && last->ir_type == ir_type_loop_jump
- && ((ir_loop_jump*) last)->is_break())
- continue_from_then_branch = true;
- else
- /* Bail out if neither if-statement branch ends with a break.
+ if (is_break(last_ir)) {
+ /* If the only loop-jump is a break at the end of the loop, the loop
+ * will execute exactly once. Remove the break, set the iteration
+ * count, and fall through to the normal unroller.
+ */
+ last_ir->remove();
+ iterations = 1;
+
+ this->progress = true;
+ } else {
+ ir_if *ir_if = NULL;
+ ir_instruction *break_ir = NULL;
+ bool continue_from_then_branch = false;
+
+ foreach_list(node, &ir->body_instructions) {
+ /* recognize loops in the form produced by ir_lower_jumps */
+ ir_instruction *cur_ir = (ir_instruction *) node;
+
+ ir_if = cur_ir->as_if();
+ if (ir_if != NULL) {
+ /* Determine which if-statement branch, if any, ends with a
+ * break. The branch that did *not* have the break will get a
+ * temporary continue inserted in each iteration of the loop
+ * unroll.
+ *
+ * Note that since ls->num_loop_jumps is <= 1, it is impossible
+ * for both branches to end with a break.