intel/compiler: Micro optimize inst_is_in_block
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 14 Mar 2023 02:46:46 +0000 (19:46 -0700)
committerMarge Bot <emma+marge@anholt.net>
Thu, 6 Apr 2023 19:07:50 +0000 (19:07 +0000)
This function only exists in builds with assertions, so it only matters
there.

On my Ice Lake laptop (using a locked CPU speed and other measures to
prevent thermal throttling, etc.) using a debugoptimized build, improves
performance of Vulkan CTS "deqp-vk --deqp-case='dEQP-VK.*spir*'" by
-5.2% ± 0.16% (n = 5, pooled s = 0.657887).

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

src/intel/compiler/brw_shader.cpp

index bf12c95..bbca348 100644 (file)
@@ -1153,11 +1153,16 @@ backend_instruction::is_volatile() const
 static bool
 inst_is_in_block(const bblock_t *block, const backend_instruction *inst)
 {
-   foreach_inst_in_block (backend_instruction, i, block) {
-      if (inst == i)
-         return true;
-   }
-   return false;
+   const exec_node *n = inst;
+
+   /* Find the tail sentinel. If the tail sentinel is the sentinel from the
+    * list header in the bblock_t, then this instruction is in that basic
+    * block.
+    */
+   while (!n->is_tail_sentinel())
+      n = n->get_next();
+
+   return n == &block->instructions.tail_sentinel;
 }
 #endif