void *const mem_ctx = ralloc_parent(ir);
loop_variable_state *const ls = this->state->get(ir);
+ /* If there are no terminators, then the loop iteration count must be 1.
+ * This is the 'do { } while (false);' case.
+ */
+ assert(!ls->terminators.is_empty() || iterations == 1);
+
ir_instruction *first_ir =
(ir_instruction *) ir->body_instructions.get_head();
* the loop, or it the exit branch contains instructions. This ensures we
* execute any instructions before the terminator or in its exit branch.
*/
- if (limit_if != first_ir->as_if() || exit_branch_has_instructions)
+ if (!ls->terminators.is_empty() &&
+ (limit_if != first_ir->as_if() || exit_branch_has_instructions))
iterations++;
for (int i = 0; i < iterations; i++) {
return visit_continue;
}
- if (ls->limiting_terminator != NULL) {
- /* If the limiting terminator has an iteration count of zero, then we've
- * proven that the loop cannot run, so delete it.
- */
- int iterations = ls->limiting_terminator->iterations;
- if (iterations == 0) {
- ir->remove();
- this->progress = true;
- return visit_continue;
- }
- }
+ /* Limiting terminator may have iteration count of zero,
+ * this is a valid case because the loop may break during
+ * the first iteration.
+ */
/* Remove the conditional break statements associated with all terminators
* that are associated with a fixed iteration count, except for the one