diff options
author | Timothy Arceri <tarceri@itsqueeze.com> | 2017-09-19 12:14:12 +1000 |
---|---|---|
committer | Timothy Arceri <tarceri@itsqueeze.com> | 2017-09-21 11:56:21 +1000 |
commit | a40b3d5a3c6bbaec03bd6978c2e174d22998b0ed (patch) | |
tree | 46f965f6abe3458a9e950252aef0a66afcb19c5f /src/compiler/glsl/loop_unroll.cpp | |
parent | e7424b2d737dd88bfb8fc09c192483ad058aefee (diff) |
glsl: merge loop_controls.cpp with loop_unroll.cpp
Having this separate just makes the code harder to follow, and
requires an extra walk of the IR.
Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
Diffstat (limited to 'src/compiler/glsl/loop_unroll.cpp')
-rw-r--r-- | src/compiler/glsl/loop_unroll.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/compiler/glsl/loop_unroll.cpp b/src/compiler/glsl/loop_unroll.cpp index dbb3fa2fa5..7eea439454 100644 --- a/src/compiler/glsl/loop_unroll.cpp +++ b/src/compiler/glsl/loop_unroll.cpp @@ -305,7 +305,6 @@ ir_visitor_status loop_unroll_visitor::visit_leave(ir_loop *ir) { loop_variable_state *const ls = this->state->get(ir); - int iterations; /* If we've entered a loop that hasn't been analyzed, something really, * really bad has happened. @@ -315,6 +314,39 @@ 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; + } + } + + /* Remove the conditional break statements associated with all terminators + * that are associated with a fixed iteration count, except for the one + * associated with the limiting terminator--that one needs to stay, since + * it terminates the loop. Exception: if the loop still has a normative + * bound, then that terminates the loop, so we don't even need the limiting + * terminator. + */ + foreach_in_list(loop_terminator, t, &ls->terminators) { + if (t->iterations < 0) + continue; + + if (t != ls->limiting_terminator) { + t->ir->remove(); + + assert(ls->num_loop_jumps > 0); + ls->num_loop_jumps--; + + this->progress = true; + } + } + if (ls->limiting_terminator == NULL) { ir_instruction *last_ir = (ir_instruction *) ir->body_instructions.get_tail(); @@ -343,7 +375,7 @@ loop_unroll_visitor::visit_leave(ir_loop *ir) return visit_continue; } - iterations = ls->limiting_terminator->iterations; + int iterations = ls->limiting_terminator->iterations; const int max_iterations = options->MaxUnrollIterations; |