glsl: In loop analysis, handle unconditional second assignment.
authorPaul Berry <stereotype441@gmail.com>
Thu, 28 Nov 2013 19:11:17 +0000 (11:11 -0800)
committerPaul Berry <stereotype441@gmail.com>
Mon, 9 Dec 2013 18:54:23 +0000 (10:54 -0800)
Previously, loop analysis would set
this->conditional_or_nested_assignment based on the most recently
visited assignment to the variable.  As a result, if a vaiable was
assigned to more than once in a loop, the flag might be set
incorrectly.  For example, in a loop like this:

    int x;
    for (int i = 0; i < 3; i++) {
      if (i == 0)
        x = 10;
      ...
      x = 20;
      ...
    }

loop analysis would have incorrectly concluded that all assignments to
x were unconditional.

In practice this was a benign bug, because
conditional_or_nested_assignment is only used to disqualify variables
from being considered as loop induction variables or loop constant
variables, and having multiple assignments also disqualifies a
variable from being considered as either of those things.

Still, we should get the analysis correct to avoid future confusion.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/loop_analysis.cpp

index c7f929590ab1e41497b398fff3c0b03995a6c4f7..9fc7672fb3948fdfe38a092ee0f8517a4d835e7d 100644 (file)
@@ -52,9 +52,10 @@ loop_variable::record_reference(bool in_assignee,
    if (in_assignee) {
       assert(current_assignment != NULL);
 
-      this->conditional_or_nested_assignment =
-         in_conditional_code_or_nested_loop
-         || current_assignment->condition != NULL;
+      if (in_conditional_code_or_nested_loop ||
+          current_assignment->condition != NULL) {
+         this->conditional_or_nested_assignment = true;
+      }
 
       if (this->first_assignment == NULL) {
          assert(this->num_assignments == 0);