pan/bi: Add SSA-based scalar copy propagation

This is a very simple (and slow...) copyprop pass. It's good enough to
get rid of redundant moves from FAU, but it doesn't help for vector
combines.

total instructions in shared programs: 175219 -> 169141 (-3.47%)
instructions in affected programs: 91439 -> 85361 (-6.65%)
helped: 599
HURT: 0
helped stats (abs) min: 1 max: 112 x̄: 10.15 x̃: 6
helped stats (rel) min: 0.30% max: 33.33% x̄: 8.61% x̃: 8.04%
95% mean confidence interval for instructions value: -11.06 -9.24
95% mean confidence interval for instructions %-change: -9.07% -8.16%
Instructions are helped.

total nops in shared programs: 120011 -> 121049 (0.86%)
nops in affected programs: 47355 -> 48393 (2.19%)
helped: 110
HURT: 309
helped stats (abs) min: 1 max: 6 x̄: 2.07 x̃: 2
helped stats (rel) min: 0.44% max: 16.67% x̄: 3.59% x̃: 3.16%
HURT stats (abs)   min: 1 max: 56 x̄: 4.10 x̃: 2
HURT stats (rel)   min: 0.32% max: 80.85% x̄: 6.85% x̃: 3.12%
95% mean confidence interval for nops value: 1.86 3.09
95% mean confidence interval for nops %-change: 3.08% 5.14%
Nops are HURT.

total clauses in shared programs: 40576 -> 40388 (-0.46%)
clauses in affected programs: 3074 -> 2886 (-6.12%)
helped: 106
HURT: 0
helped stats (abs) min: 1 max: 4 x̄: 1.77 x̃: 2
helped stats (rel) min: 0.42% max: 22.22% x̄: 7.17% x̃: 6.90%
95% mean confidence interval for clauses value: -1.91 -1.63
95% mean confidence interval for clauses %-change: -7.80% -6.53%
Clauses are helped.

total quadwords in shared programs: 146590 -> 144937 (-1.13%)
quadwords in affected programs: 59475 -> 57822 (-2.78%)
helped: 493
HURT: 1
helped stats (abs) min: 1 max: 28 x̄: 3.35 x̃: 2
helped stats (rel) min: 0.28% max: 15.38% x̄: 4.08% x̃: 3.85%
HURT stats (abs)   min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel)   min: 2.38% max: 2.38% x̄: 2.38% x̃: 2.38%
95% mean confidence interval for quadwords value: -3.61 -3.08
95% mean confidence interval for quadwords %-change: -4.33% -3.81%
Quadwords are helped.

total spills in shared programs: 1106 -> 1106 (0.00%)
spills in affected programs: 0 -> 0
helped: 0
HURT: 0

total fills in shared programs: 2241 -> 2241 (0.00%)
fills in affected programs: 0 -> 0
helped: 0
HURT: 0

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8973>
This commit is contained in:
Alyssa Rosenzweig 2021-02-10 11:47:24 -05:00 committed by Marge Bot
parent fa79168b9e
commit 040a350b1e
5 changed files with 69 additions and 0 deletions

View file

@ -9,6 +9,7 @@ bifrost_FILES := \
bifrost/bi_print.c \
bifrost/bi_print.h \
bifrost/bi_ra.c \
bifrost/bi_opt_copy_prop.c \
bifrost/bi_opt_dce.c \
bifrost/bi_quirks.h \
bifrost/bi_test_pack.c \

View file

@ -0,0 +1,64 @@
/*
* Copyright (C) 2018 Alyssa Rosenzweig
* Copyright (C) 2019-2020 Collabora, Ltd.
*
* 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.
*/
#include "compiler.h"
/* A simple scalar-only SSA-based copy-propagation pass. O(N^2) due to the lack
* of use tracking. TODO: better data structures for O(N), TODO: vectors */
static bool
bi_rewrite_scalar_uses(bi_context *ctx, bi_index old, bi_index new)
{
bool progress = false;
bi_foreach_instr_global(ctx, use) {
bi_foreach_src(use, s) {
bi_index src = use->src[s];
bool scalar = (bi_count_read_registers(use, s) == 1);
if (bi_is_word_equiv(src, old) && scalar) {
use->src[s] = bi_replace_index(src, new);
progress = true;
}
}
}
return progress;
}
bool
bi_opt_copy_prop(bi_context *ctx)
{
bool progress = false;
bi_foreach_instr_global_safe(ctx, ins) {
if (ins->op != BI_OPCODE_MOV_I32) continue;
if (!bi_is_ssa(ins->dest[0])) continue;
if (!(bi_is_ssa(ins->src[0]) || ins->src[0].type == BI_INDEX_FAU)) continue;
progress |= bi_rewrite_scalar_uses(ctx, ins->dest[0], ins->src[0]);
}
return progress;
}

View file

@ -2517,6 +2517,8 @@ bifrost_compile_shader_nir(void *mem_ctx, nir_shader *nir,
do {
progress = false;
progress |= bi_opt_copy_prop(ctx);
bi_foreach_block(ctx, _block) {
bi_block *block = (bi_block *) _block;
progress |= bi_opt_dead_code_eliminate(ctx, block, false);

View file

@ -746,6 +746,7 @@ void bi_print_shader(bi_context *ctx, FILE *fp);
/* BIR passes */
bool bi_opt_copy_prop(bi_context *ctx);
bool bi_opt_dead_code_eliminate(bi_context *ctx, bi_block *block, bool soft);
void bi_schedule(bi_context *ctx);
void bi_register_allocate(bi_context *ctx);

View file

@ -23,6 +23,7 @@ libpanfrost_bifrost_files = files(
'bi_layout.c',
'bi_liveness.c',
'bi_print.c',
'bi_opt_copy_prop.c',
'bi_opt_dce.c',
'bi_pack.c',
'bi_ra.c',