From 7850ce0a9990c7f752e43a1dd88c204a7cf090aa Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 27 Aug 2010 11:26:08 -0700 Subject: glsl2: Eliminate zero-iteration loops --- src/glsl/loop_controls.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/glsl/loop_controls.cpp') diff --git a/src/glsl/loop_controls.cpp b/src/glsl/loop_controls.cpp index 2eddb91364..9eb1a8901b 100644 --- a/src/glsl/loop_controls.cpp +++ b/src/glsl/loop_controls.cpp @@ -234,7 +234,7 @@ loop_control_visitor::visit_leave(ir_loop *ir) const int iterations = calculate_iterations(init, limit, lv->increment, cmp); - if (iterations > 0) { + if (iterations >= 0) { /* If the new iteration count is lower than the previously * believed iteration count, update the loop control values. */ @@ -267,6 +267,12 @@ loop_control_visitor::visit_leave(ir_loop *ir) } } + /* If we have proven the one of the loop exit conditions is satisifed before + * running the loop once, remove the loop. + */ + if (max_iterations == 0) + ir->remove(); + return visit_continue; } -- cgit v1.2.3