glsl/loops: Remove unnecessary list walk from loop_control_visitor.
authorPaul Berry <stereotype441@gmail.com>
Thu, 28 Nov 2013 20:44:53 +0000 (12:44 -0800)
committerPaul Berry <stereotype441@gmail.com>
Mon, 9 Dec 2013 18:54:49 +0000 (10:54 -0800)
When loop_control_visitor::visit_leave(ir_loop *) is analyzing a loop
terminator that acts on a certain ir_variable, it doesn't need to walk
the list of induction variables to find the loop_variable entry
corresponding to the variable.  It can just look it up in the
loop_variable_state hashtable and verify that the loop_variable entry
represents an induction variable.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/loop_analysis.h
src/glsl/loop_controls.cpp

index 961ea40c079a19b44298c590d9c9143535209c19..8e57dacbf6b6beb9b92465cdd172aab6c029ac19 100644 (file)
@@ -189,6 +189,15 @@ public:
    ir_rvalue *increment;
 
 
+   inline bool is_induction_var() const
+   {
+      /* Induction variables always have a non-null increment, and vice
+       * versa.
+       */
+      return this->increment != NULL;
+   }
+
+
    inline bool is_loop_constant() const
    {
       const bool is_const = (this->num_assignments == 0)
index a1dc20e719853a59354735a79242817410c76aef..ce05e09a6ab890575b4824ebe28a3614975f63bd 100644 (file)
@@ -237,39 +237,36 @@ loop_control_visitor::visit_leave(ir_loop *ir)
 
         ir_rvalue *init = find_initial_value(ir, var);
 
-        foreach_list(iv_node, &ls->induction_variables) {
-           loop_variable *lv = (loop_variable *) iv_node;
-
-           if (lv->var == var) {
-              const int iterations = calculate_iterations(init, limit,
-                                                          lv->increment,
-                                                          cmp);
-              if (iterations >= 0) {
-                 /* If the new iteration count is lower than the previously
-                  * believed iteration count, then add a normative bound to
-                  * this loop.
-                  */
-                 if ((unsigned) iterations < max_iterations) {
-                     ir->normative_bound = iterations;
-
-                    max_iterations = iterations;
-                 }
-
-                 /* Remove the conditional break statement.  The loop
-                  * controls are now set such that the exit condition will be
-                  * satisfied.
-                  */
-                 if_stmt->remove();
-
-                 assert(ls->num_loop_jumps > 0);
-                 ls->num_loop_jumps--;
-
-                 this->progress = true;
-              }
-
-              break;
-           }
-        }
+         loop_variable *lv = ls->get(var);
+         if (lv != NULL && lv->is_induction_var()) {
+            const int iterations = calculate_iterations(init, limit,
+                                                        lv->increment,
+                                                        cmp);
+            if (iterations >= 0) {
+               /* If the new iteration count is lower than the previously
+                * believed iteration count, then add a normative bound to
+                * this loop.
+                */
+               if ((unsigned) iterations < max_iterations) {
+                  ir->normative_bound = iterations;
+
+                  max_iterations = iterations;
+               }
+
+               /* Remove the conditional break statement.  The loop
+                * controls are now set such that the exit condition will be
+                * satisfied.
+                */
+               if_stmt->remove();
+
+               assert(ls->num_loop_jumps > 0);
+               ls->num_loop_jumps--;
+
+               this->progress = true;
+            }
+
+            break;
+         }
         break;
       }