glsl: fix the type of ir_constant_data::u16
[mesa.git] / src / compiler / glsl / loop_unroll.cpp
index 874f4185681d1a44d866b64930f3f30beb4a60c2..1a9229acc345c4263f1cca8a35eba6c4f45db06b 100644 (file)
@@ -180,6 +180,11 @@ loop_unroll_visitor::simple_unroll(ir_loop *ir, int iterations)
    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();
 
@@ -221,7 +226,8 @@ loop_unroll_visitor::simple_unroll(ir_loop *ir, int iterations)
     * 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++) {
@@ -384,17 +390,10 @@ loop_unroll_visitor::visit_leave(ir_loop *ir)
       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