[Mesa-dev] [PATCH 07/10] nir: return early when lowering a return at the end of a function

Timothy Arceri tarceri at itsqueeze.com
Tue Apr 10 04:34:32 UTC 2018


Otherwise we create unused conditional return flags and things
get unnecessarily ugly fast when lowering nested functions.
---
 src/compiler/nir/nir_lower_returns.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/compiler/nir/nir_lower_returns.c b/src/compiler/nir/nir_lower_returns.c
index 423192adb8a..e1ba5f2ad64 100644
--- a/src/compiler/nir/nir_lower_returns.c
+++ b/src/compiler/nir/nir_lower_returns.c
@@ -27,6 +27,7 @@
 
 struct lower_returns_state {
    nir_builder builder;
+   nir_function_impl *impl;
    struct exec_list *cf_list;
    nir_loop *loop;
    nir_variable *return_flag;
@@ -180,6 +181,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->impl))
+      return true;
+
    nir_builder *b = &state->builder;
 
    /* Set the return flag */
@@ -252,6 +259,7 @@ nir_lower_returns_impl(nir_function_impl *impl)
 {
    struct lower_returns_state state;
 
+   state.impl = impl;
    state.cf_list = &impl->body;
    state.loop = NULL;
    state.return_flag = NULL;
-- 
2.17.0



More information about the mesa-dev mailing list