Mesa (master): nir/gcm: be more conservative about moving instructions from loops

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Apr 20 04:38:56 UTC 2020


Module: Mesa
Branch: master
Commit: e4e5beee8a4cc0f7a6b27ce1ea1e04d1177442a1
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e4e5beee8a4cc0f7a6b27ce1ea1e04d1177442a1

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Mon Mar 25 19:38:54 2019 +1100

nir/gcm: be more conservative about moving instructions from loops

Here we only pull instructions further up control flow if they are
constant or texture instructions. See the code comment for more
information.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4636>

---

 src/compiler/nir/nir_opt_gcm.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir_opt_gcm.c b/src/compiler/nir/nir_opt_gcm.c
index 0d4c23ab631..9a337c9a97f 100644
--- a/src/compiler/nir/nir_opt_gcm.c
+++ b/src/compiler/nir/nir_opt_gcm.c
@@ -277,8 +277,22 @@ gcm_choose_block_for_instr(nir_instr *instr, nir_block *early_block,
 
    nir_block *best = late_block;
    for (nir_block *block = late_block; block != NULL; block = block->imm_dom) {
+      /* Being too aggressive with how we pull instructions out of loops can
+       * result in extra register pressure and spilling. For example its fairly
+       * common for loops in compute shaders to calculate SSBO offsets using
+       * the workgroup id, subgroup id and subgroup invocation, pulling all
+       * these calculations outside the loop causes register pressure.
+       *
+       * To work around these issues for now we only allow constant and texture
+       * instructions to be moved outside their original loops.
+       *
+       * TODO: figure out some heuristics to allow more to be moved out of loops.
+       */
       if (state->blocks[block->index].loop_depth <
-          state->blocks[best->index].loop_depth)
+          state->blocks[best->index].loop_depth &&
+          (nir_block_dominates(instr->block, block) ||
+           instr->type == nir_instr_type_load_const ||
+           instr->type == nir_instr_type_tex))
          best = block;
       else if (block == instr->block)
          best = block;



More information about the mesa-commit mailing list