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 <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11628>
This commit is contained in:
Emma Anholt 2021-06-28 10:51:06 -07:00
parent 5251548572
commit 5618445d45
2 changed files with 6 additions and 2 deletions

View file

@ -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);

View file

@ -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.