loop_controls: fix analysis of already analyzed loops
authorLuca Barbieri <luca@luca-barbieri.com>
Tue, 7 Sep 2010 15:02:37 +0000 (17:02 +0200)
committerIan Romanick <ian.d.romanick@intel.com>
Mon, 13 Sep 2010 20:03:10 +0000 (13:03 -0700)
The loop_controls pass didn't look at the counter values it put in ir_loop
on previous iterations, so while the first iteration worked, subsequent
ones couldn't determine max_iterations.

src/glsl/loop_controls.cpp

index 17a0d2db816e09e835c2eabbe5d965b3f67de36a..9619d8ae55540fb2e8e5e081e7915972335e4676 100644 (file)
@@ -182,7 +182,14 @@ loop_control_visitor::visit_leave(ir_loop *ir)
     * i is a loop induction variable, c is a constant, and < is any relative
     * operator.
     */
-   int max_iterations = (ls->max_iterations < 0) ? INT_MAX : ls->max_iterations;
+   int max_iterations = ls->max_iterations;
+
+   if(ir->from && ir->to && ir->increment)
+      max_iterations = calculate_iterations(ir->from, ir->to, ir->increment, (ir_expression_operation)ir->cmp);
+
+   if(max_iterations < 0)
+      max_iterations = INT_MAX;
+
    foreach_list(node, &ls->terminators) {
       loop_terminator *t = (loop_terminator *) node;
       ir_if *if_stmt = t->ir;