glsl: Lower unconditional return statements.
authorPaul Berry <stereotype441@gmail.com>
Fri, 1 Jul 2011 19:14:07 +0000 (12:14 -0700)
committerPaul Berry <stereotype441@gmail.com>
Fri, 8 Jul 2011 16:59:30 +0000 (09:59 -0700)
Previously, lower_jumps.cpp only lowered return statements that
appeared inside of an if statement.

Without this patch, lower_jumps.cpp might not lower certain return
statements, causing some back-ends to fail (as in bug #36669).

Fixes unit test test_lower_returns_1.

src/glsl/lower_jumps.cpp

index fa247c6c9b92d4cb4ac5c37538f2e8ae48f82e3a..eceba09266e31a382ac866ce1ac28a920cfc5853 100644 (file)
@@ -851,6 +851,20 @@ lower_continue:
        */
       visit_block(&ir->body);
 
+      /* If the body ended in an unconditional return of non-void,
+       * then we don't need to lower it because it's the one canonical
+       * return.
+       *
+       * If the body ended in a return of void, eliminate it because
+       * it is redundant.
+       */
+      if (ir->return_type->is_void() &&
+          get_jump_strength((ir_instruction *) ir->body.get_tail())) {
+         ir_jump *jump = (ir_jump *) ir->body.get_tail();
+         assert (jump->ir_type == ir_type_return);
+         jump->remove();
+      }
+
       if(this->function.return_value)
          ir->body.push_tail(new(ir) ir_return(new (ir) ir_dereference_variable(this->function.return_value)));