From 5618445d4541ae3cc26f75bef37a549d3bd9767c Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Mon, 28 Jun 2021 10:51:06 -0700 Subject: [PATCH] nir: Use remove_and_dce for nir_shader_lower_instructions(). Reduces the work that other shader passes have to do to look at dead code, and possibly extra rounds around the optimization loop if dce wasn't the last pass in it. shader-db runtime -1.12919% +/- 0.264337% (n=49) on SKL. Reviewed-by: Ian Romanick Part-of: --- src/compiler/nir/nir.c | 4 ++-- src/compiler/nir/nir.h | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index 9fef5b1f71d..d9757ec1b66 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -2003,7 +2003,7 @@ nir_function_impl_lower_instructions(nir_function_impl *impl, nir_if_rewrite_condition(use_src->parent_if, new_src); if (nir_ssa_def_is_unused(old_def)) { - iter = nir_instr_remove(instr); + iter = nir_instr_remove_and_dce(instr); } else { iter = nir_after_instr(instr); } @@ -2017,7 +2017,7 @@ nir_function_impl_lower_instructions(nir_function_impl *impl, if (new_def == NIR_LOWER_INSTR_PROGRESS_REPLACE) { /* Only instructions without a return value can be removed like this */ assert(!old_def); - iter = nir_instr_remove(instr); + iter = nir_instr_remove_and_dce(instr); progress = true; } else iter = nir_after_instr(instr); diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index d45c5505e68..5d123ab76f4 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -4314,6 +4314,10 @@ typedef nir_ssa_def *(*nir_lower_instr_cb)(struct nir_builder *, * will be removed. If new instructions are added, the lowering callback will * also be called on them in case multiple lowerings are required. * + * If the callback indicates that the original instruction is replaced (either + * through a new SSA def or NIR_LOWER_INSTR_PROGRESS_REPLACE), then the + * instruction is removed along with any now-dead SSA defs it used. + * * The metadata for the nir_function_impl will also be updated. If any blocks * are added (they cannot be removed), dominance and block indices will be * invalidated.