glsl: Remove optimize_swizzles.
authorEmma Anholt <emma@anholt.net>
Tue, 19 Jul 2022 05:12:36 +0000 (22:12 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 20 Jul 2022 20:45:09 +0000 (20:45 +0000)
It will get turned into SSA and copy-propagated in NIR, no need to walk
the IR collapsing it here.

iris shader-db results appear to be noise:

total instructions in shared programs: 8932195 -> 8932147 (<.01%)
instructions in affected programs: 537 -> 489 (-8.94%)
LOST:   12
GAINED: 11

lost/gained are simd32 switches in unigine, l4d2, portal2, asphalt9.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17613>

src/compiler/glsl/glsl_parser_extras.cpp
src/compiler/glsl/ir_optimization.h
src/compiler/glsl/meson.build
src/compiler/glsl/opt_swizzle.cpp [deleted file]
src/compiler/glsl/test_optpass.cpp
src/gallium/drivers/virgl/ci/traces-virgl.yml

index 5f8eb70..1f26938 100644 (file)
@@ -2415,7 +2415,6 @@ do_common_optimization(exec_list *ir, bool linked,
        options->EmitNoCont);
    OPT(do_vec_index_to_swizzle, ir);
    OPT(lower_vector_insert, ir, false);
-   OPT(optimize_swizzles, ir);
 
    /* Some drivers only call do_common_optimization() once rather than in a
     * loop, and split arrays causes each element of a constant array to
index 52143d5..25583b2 100644 (file)
@@ -105,7 +105,6 @@ bool opt_flatten_nested_if_blocks(exec_list *instructions);
 bool do_mat_op_to_vec(exec_list *instructions);
 bool do_minmax_prune(exec_list *instructions);
 bool do_structure_splitting(exec_list *instructions);
-bool optimize_swizzles(exec_list *instructions);
 bool do_tree_grafting(exec_list *instructions);
 bool do_vec_index_to_cond_assign(exec_list *instructions);
 bool do_vec_index_to_swizzle(exec_list *instructions);
index ce88990..e944469 100644 (file)
@@ -194,7 +194,6 @@ files_libglsl = files(
   'opt_minmax.cpp',
   'opt_rebalance_tree.cpp',
   'opt_structure_splitting.cpp',
-  'opt_swizzle.cpp',
   'opt_tree_grafting.cpp',
   'program.h',
   'propagate_invariance.cpp',
diff --git a/src/compiler/glsl/opt_swizzle.cpp b/src/compiler/glsl/opt_swizzle.cpp
deleted file mode 100644 (file)
index 2fbe362..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright © 2010 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file opt_swizzle.cpp
- * Optimize swizzle operations.
- *
- * First, compact a sequence of swizzled swizzles into a single swizzle.
- *
- * If the final resulting swizzle doesn't change the order or count of
- * components, then remove the swizzle so that other optimization passes see
- * the value behind it.
- */
-
-#include "ir.h"
-#include "ir_visitor.h"
-#include "ir_rvalue_visitor.h"
-#include "compiler/glsl_types.h"
-
-namespace {
-
-class ir_opt_swizzle_visitor : public ir_rvalue_visitor {
-public:
-   ir_opt_swizzle_visitor()
-   {
-      this->progress = false;
-   }
-
-   void handle_rvalue(ir_rvalue **rvalue);
-   bool progress;
-};
-
-} /* unnamed namespace */
-
-void
-ir_opt_swizzle_visitor::handle_rvalue(ir_rvalue **rvalue)
-{
-   if (!*rvalue)
-      return;
-
-   ir_swizzle *swiz = (*rvalue)->as_swizzle();
-
-   if (!swiz)
-      return;
-
-   ir_swizzle *swiz2;
-
-   while ((swiz2 = swiz->val->as_swizzle()) != NULL) {
-      int mask2[4];
-
-      memset(&mask2, 0, sizeof(mask2));
-      if (swiz2->mask.num_components >= 1)
-         mask2[0] = swiz2->mask.x;
-      if (swiz2->mask.num_components >= 2)
-         mask2[1] = swiz2->mask.y;
-      if (swiz2->mask.num_components >= 3)
-         mask2[2] = swiz2->mask.z;
-      if (swiz2->mask.num_components >= 4)
-         mask2[3] = swiz2->mask.w;
-
-      if (swiz->mask.num_components >= 1)
-         swiz->mask.x = mask2[swiz->mask.x];
-      if (swiz->mask.num_components >= 2)
-         swiz->mask.y = mask2[swiz->mask.y];
-      if (swiz->mask.num_components >= 3)
-         swiz->mask.z = mask2[swiz->mask.z];
-      if (swiz->mask.num_components >= 4)
-         swiz->mask.w = mask2[swiz->mask.w];
-
-      swiz->val = swiz2->val;
-
-      this->progress = true;
-   }
-
-   if (swiz->type != swiz->val->type)
-      return;
-
-   int elems = swiz->val->type->vector_elements;
-   if (swiz->mask.x != 0)
-      return;
-   if (elems >= 2 && swiz->mask.y != 1)
-      return;
-   if (elems >= 3 && swiz->mask.z != 2)
-      return;
-   if (elems >= 4 && swiz->mask.w != 3)
-      return;
-
-   this->progress = true;
-   *rvalue = swiz->val;
-}
-
-bool
-optimize_swizzles(exec_list *instructions)
-{
-   ir_opt_swizzle_visitor v;
-   visit_list_elements(&v, instructions);
-
-   return v.progress;
-}
index bb894a0..da72ff6 100644 (file)
@@ -95,8 +95,6 @@ do_optimization(struct exec_list *ir, const char *optimization,
       return do_if_simplification(ir);
    } else if (strcmp(optimization, "do_mat_op_to_vec") == 0) {
       return do_mat_op_to_vec(ir);
-   } else if (strcmp(optimization, "optimize_swizzles") == 0) {
-      return optimize_swizzles(ir);
    } else if (strcmp(optimization, "do_structure_splitting") == 0) {
       return do_structure_splitting(ir);
    } else if (strcmp(optimization, "do_tree_grafting") == 0) {
index 26647eb..a015fd5 100644 (file)
@@ -17,7 +17,7 @@ traces:
   - path: gputest/furmark-v2.trace
     expectations:
       - device: gl-virgl
-        checksum: 2762c809316c58d4eefad6677ecfcb2e
+        checksum: 57ddd36b117adc9216c65c10d914a37e
   - path: gputest/pixmark-piano-v2.trace
     expectations:
       - device: gl-virgl