diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index ed7e8f7f948..9622085a0d0 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -970,6 +970,13 @@ nir_src_is_const(nir_src src) src.ssa->parent_instr->type == nir_instr_type_load_const; } +static inline bool +nir_src_is_undef(nir_src src) +{ + return src.is_ssa && + src.ssa->parent_instr->type == nir_instr_type_ssa_undef; +} + static inline bool nir_src_is_divergent(nir_src src) { diff --git a/src/compiler/nir/nir_divergence_analysis.c b/src/compiler/nir/nir_divergence_analysis.c index 7c0fc129740..fa9cf811889 100644 --- a/src/compiler/nir/nir_divergence_analysis.c +++ b/src/compiler/nir/nir_divergence_analysis.c @@ -746,7 +746,7 @@ visit_loop_header_phi(nir_phi_instr *phi, nir_block *preheader, bool divergent_c if (src->pred == preheader) continue; /* skip undef values */ - if (src->src.ssa->parent_instr->type == nir_instr_type_ssa_undef) + if (nir_src_is_undef(src->src)) continue; /* check if all loop-carried values are from the same ssa-def */ diff --git a/src/compiler/nir/nir_gather_ssa_types.c b/src/compiler/nir/nir_gather_ssa_types.c index c7c073c508c..ed1ee8aac4b 100644 --- a/src/compiler/nir/nir_gather_ssa_types.c +++ b/src/compiler/nir/nir_gather_ssa_types.c @@ -72,8 +72,7 @@ static void copy_types(nir_src src, nir_dest *dest, BITSET_WORD *float_types, BITSET_WORD *int_types, bool *progress) { - bool src_is_sink = nir_src_is_const(src) || - src.ssa->parent_instr->type == nir_instr_type_ssa_undef; + bool src_is_sink = nir_src_is_const(src) || nir_src_is_undef(src); copy_type(src.ssa->index, dest->ssa.index, src_is_sink, float_types, progress); copy_type(src.ssa->index, dest->ssa.index, src_is_sink, int_types, progress); } diff --git a/src/compiler/nir/nir_liveness.c b/src/compiler/nir/nir_liveness.c index c748db64420..941ed1cfa1d 100644 --- a/src/compiler/nir/nir_liveness.c +++ b/src/compiler/nir/nir_liveness.c @@ -77,7 +77,7 @@ set_src_live(nir_src *src, void *void_live) if (!src->is_ssa) return true; - if (src->ssa->parent_instr->type == nir_instr_type_ssa_undef) + if (nir_src_is_undef(*src)) return true; /* undefined variables are never live */ BITSET_SET(live, src->ssa->index); diff --git a/src/compiler/nir/nir_opt_remove_phis.c b/src/compiler/nir/nir_opt_remove_phis.c index db58c618f6b..97cdcfecf38 100644 --- a/src/compiler/nir/nir_opt_remove_phis.c +++ b/src/compiler/nir/nir_opt_remove_phis.c @@ -98,7 +98,7 @@ remove_phis_block(nir_block *block, nir_builder *b) if (def == NULL) { def = src->src.ssa; mov = get_parent_mov(def); - } else if (src->src.ssa->parent_instr->type == nir_instr_type_ssa_undef && + } else if (nir_src_is_undef(src->src) && nir_block_dominates(def->parent_instr->block, src->pred)) { /* Ignore this undef source. */ } else { diff --git a/src/intel/compiler/brw_fs_nir.cpp b/src/intel/compiler/brw_fs_nir.cpp index 91a92d44b10..05ab5a69971 100644 --- a/src/intel/compiler/brw_fs_nir.cpp +++ b/src/intel/compiler/brw_fs_nir.cpp @@ -1918,7 +1918,7 @@ fs_visitor::get_nir_src(const nir_src &src) { fs_reg reg; if (src.is_ssa) { - if (src.ssa->parent_instr->type == nir_instr_type_ssa_undef) { + if (nir_src_is_undef(src)) { const brw_reg_type reg_type = brw_reg_type_from_bit_size(src.ssa->bit_size, BRW_REGISTER_TYPE_D); reg = bld.vgrf(reg_type, src.ssa->num_components);