intel/fs: Linked list micro optimizations in brw_nir_move_interpolation_to_top
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 21 Mar 2023 03:57:47 +0000 (20:57 -0700)
committerMarge Bot <emma+marge@anholt.net>
Thu, 6 Apr 2023 19:07:50 +0000 (19:07 +0000)
Two linked list management changes:

- Use the list head sentinel as the initial cursor. It is, after all, a
  proper node in the list.

- Iterate the list of blocks starting with the second block instead of
  skipping the first block in the loop.

On my Ice Lake laptop (using a locked CPU speed and other measures to
prevent thermal throttling, etc.) using a release build, improves
performance of compiling shaders from batman_arkham_city_goty.foz by
-0.24% ± 0.09% (n = 5, pooled s = 0.324106).

v2: Use nir_cursor instead of direct list manipultion. Suggested by
Lionel.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22299>

src/intel/compiler/brw_fs.cpp

index 8d2db7e..bf32b32 100644 (file)
@@ -7261,11 +7261,11 @@ brw_nir_move_interpolation_to_top(nir_shader *nir)
          continue;
 
       nir_block *top = nir_start_block(f->impl);
-      exec_node *cursor_node = NULL;
+      nir_cursor cursor = nir_before_instr(nir_block_first_instr(top));
 
-      nir_foreach_block(block, f->impl) {
-         if (block == top)
-            continue;
+      for (nir_block *block = nir_block_cf_tree_next(top);
+           block != NULL;
+           block = nir_block_cf_tree_next(block)) {
 
          nir_foreach_instr_safe(instr, block) {
             if (instr->type != nir_instr_type_intrinsic)
@@ -7291,14 +7291,7 @@ brw_nir_move_interpolation_to_top(nir_shader *nir)
 
             for (unsigned i = 0; i < ARRAY_SIZE(move); i++) {
                if (move[i]->block != top) {
-                  move[i]->block = top;
-                  exec_node_remove(&move[i]->node);
-                  if (cursor_node) {
-                     exec_node_insert_after(cursor_node, &move[i]->node);
-                  } else {
-                     exec_list_push_head(&top->instr_list, &move[i]->node);
-                  }
-                  cursor_node = &move[i]->node;
+                  nir_instr_move(cursor, move[i]);
                   progress = true;
                }
             }