nir: return early when lowering a return at the end of a function
authorTimothy Arceri <tarceri@itsqueeze.com>
Sun, 8 Apr 2018 11:47:32 +0000 (21:47 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Tue, 17 Apr 2018 04:17:56 +0000 (14:17 +1000)
Otherwise we create unused conditional return flags and things
get unnecessarily ugly fast when lowering nested functions.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_lower_returns.c

index 423192adb8a2286dd395f0522466c84e4cf6fe18..3ea69e25204855b1cc79157d0083ab8b4353e2e1 100644 (file)
@@ -180,6 +180,12 @@ lower_returns_in_block(nir_block *block, struct lower_returns_state *state)
 
    nir_instr_remove(&jump->instr);
 
+   /* If this is a return in the last block of the function there is nothing
+    * more to do once its removed.
+    */
+   if (block == nir_impl_last_block(state->builder.impl))
+      return true;
+
    nir_builder *b = &state->builder;
 
    /* Set the return flag */