From 74aea0b840334984255753fe19e0f03839ec2b82 Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Mon, 18 Jul 2022 22:12:36 -0700 Subject: [PATCH] glsl: Remove optimize_swizzles. 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 Reviewed-by: Ian Romanick Reviewed-by: Timothy Arceri Part-of: --- src/compiler/glsl/glsl_parser_extras.cpp | 1 - src/compiler/glsl/ir_optimization.h | 1 - src/compiler/glsl/meson.build | 1 - src/compiler/glsl/opt_swizzle.cpp | 119 ------------------ src/compiler/glsl/test_optpass.cpp | 2 - src/gallium/drivers/virgl/ci/traces-virgl.yml | 2 +- 6 files changed, 1 insertion(+), 125 deletions(-) delete mode 100644 src/compiler/glsl/opt_swizzle.cpp diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp index 5f8eb70b459..1f269382714 100644 --- a/src/compiler/glsl/glsl_parser_extras.cpp +++ b/src/compiler/glsl/glsl_parser_extras.cpp @@ -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 diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h index 52143d5f366..25583b27317 100644 --- a/src/compiler/glsl/ir_optimization.h +++ b/src/compiler/glsl/ir_optimization.h @@ -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); diff --git a/src/compiler/glsl/meson.build b/src/compiler/glsl/meson.build index ce889904e60..e9444699cd9 100644 --- a/src/compiler/glsl/meson.build +++ b/src/compiler/glsl/meson.build @@ -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 index 2fbe3621880..00000000000 --- a/src/compiler/glsl/opt_swizzle.cpp +++ /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; -} diff --git a/src/compiler/glsl/test_optpass.cpp b/src/compiler/glsl/test_optpass.cpp index bb894a03a49..da72ff6adf7 100644 --- a/src/compiler/glsl/test_optpass.cpp +++ b/src/compiler/glsl/test_optpass.cpp @@ -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) { diff --git a/src/gallium/drivers/virgl/ci/traces-virgl.yml b/src/gallium/drivers/virgl/ci/traces-virgl.yml index 26647eb337c..a015fd5fccc 100644 --- a/src/gallium/drivers/virgl/ci/traces-virgl.yml +++ b/src/gallium/drivers/virgl/ci/traces-virgl.yml @@ -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