glsl: Fix unroll of do{} while(false) like loops

For loops which condition is false on the first iteration
iteration count was falsely calculated under the assumption
that loop's condition is true until it becomes false, meaning
it's true at least one time.
Now such loops are reported as having 0 iteration.

Similar to the fix e71fc7f2 done in NIR.

Fixes tests/shaders/glsl-fs-loop-while-false-02.shader_test

Signed-off-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:
Danylo Piliaiev
2019-08-22 13:32:50 +03:00
committed by Timothy Arceri
parent 3debd0ef15
commit aabde02f2f
2 changed files with 41 additions and 17 deletions

View File

@@ -390,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