intel/fs: Avoid generating useless UNDEFs for every SSA def

Emitting UNDEF is only necessary when the instructions we generate to
produce the NIR def are considered partial writes.  By adding a simple
check (adapted from fs_inst::is_partial_write()), we can avoid creating
loads of unnecessary UNDEFs that we have to clean up later.

Our first dead code elimination pass does get rid of them pretty
quickly, but this should save memory and time during our first
split_virtual_grfs and dead_code_elimination passes.

This generates roughly 30% fewer instructions at the beginning.

Improves compilation time of shaders:
- Rise of the Tomb Raider: -3.51563% +/- 0.103951% (n=7)
- Borderlands 3: -3.64422% +/- 0.300951% (n=7).

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28169>
This commit is contained in:
Kenneth Graunke 2024-02-26 22:50:08 -08:00 committed by Marge Bot
parent a6b93c50d0
commit d473004576

View file

@ -2081,7 +2081,10 @@ get_nir_def(nir_to_brw_state &ntb, const nir_def &def)
BRW_REGISTER_TYPE_F);
ntb.ssa_values[def.index] =
bld.vgrf(reg_type, def.num_components);
bld.UNDEF(ntb.ssa_values[def.index]);
if (def.bit_size * bld.dispatch_width() < 8 * REG_SIZE)
bld.UNDEF(ntb.ssa_values[def.index]);
return ntb.ssa_values[def.index];
} else {
nir_intrinsic_instr *decl_reg =