From eff9f0053383b9b5f8f2880f5d1d95cd1154e198 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Mon, 30 Mar 2026 17:12:35 +0200 Subject: [PATCH] nir/search: remove matching variable type Now unused, and if you really need it use a search helper. Reviewed-by: Ian Romanick Part-of: --- src/compiler/nir/nir_algebraic.py | 34 +++----------------- src/compiler/nir/nir_opt_algebraic.py | 4 +-- src/compiler/nir/nir_search.c | 46 --------------------------- src/compiler/nir/nir_search.h | 12 ------- 4 files changed, 6 insertions(+), 90 deletions(-) diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 456332f9f0b..cae33611467 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -202,7 +202,6 @@ class Value(object): % elif isinstance(val, Variable): ${val.index}, /* ${val.var_name} */ ${'true' if val.is_constant else 'false'}, - ${val.type() or 'nir_type_invalid' }, ${val.cond_index}, ${val.swizzle()}, % elif isinstance(val, Expression): @@ -295,7 +294,7 @@ class Constant(Value): # The $ at the end forces there to be an error if any part of the string # doesn't match one of the field patterns. _var_name_re = re.compile(r"(?P#)?(?P\w+)" - r"(?:@(?Pint|uint|bool|float)?(?P\d+)?)?" + r"(?P@\d+)?" r"(?P\([^\)]+\))?" r"(?P\.[xyzwabcdefghijklmnop]+)?" r"$") @@ -328,29 +327,11 @@ class Variable(Value): self.cond = m.group('cond') self.cond_index = get_cond_index( algebraic_pass.variable_cond, m.group('cond')) - self.required_type = m.group('type') - self._bit_size = int(m.group('bits')) if m.group('bits') else None + self._bit_size = int(m.group('bits')[1:]) if m.group('bits') else None self.swiz = m.group('swiz') - if self.required_type == 'bool': - if self._bit_size is not None: - assert self._bit_size in type_sizes(self.required_type) - else: - self._bit_size = 1 - - if self.required_type is not None: - assert self.required_type in ('float', 'bool', 'int', 'uint') - self.index = varset[self.var_name] - def type(self): - if self.required_type == 'bool': - return "nir_type_bool" - elif self.required_type in ('int', 'uint'): - return "nir_type_int" - elif self.required_type == 'float': - return "nir_type_float" - def equivalent(self, other): """Check that two variables are equivalent. @@ -822,9 +803,6 @@ class BitSizeValidator(object): assert val.cond_index == -1, \ 'Replacement variables must not have a condition.' - assert not val.required_type, \ - 'Replacement variables must not have a required type.' - def validate(self, search, replace): self.is_search = True self.merge_variables(search) @@ -1436,12 +1414,8 @@ def get_expression_def(expr, name, value_comps, variable_map, defs, expr_conds, def_name = f"{name}{len(defs)}" num_components = value_comps[expr.index] - if expr.required_type == "bool": - defs.append( - f"nir_def *{def_name} = nir_b2b{bit_size}(b, nir_unit_test_uniform_input(b, {num_components}, 1, {expr.index}));") - else: - defs.append( - f"nir_def *{def_name} = nir_unit_test_uniform_input(b, {num_components}, {bit_size}, {expr.index});") + defs.append( + f"nir_def *{def_name} = nir_unit_test_uniform_input(b, {num_components}, {bit_size}, {expr.index});") variable_map[expr.index] = def_name else: diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 4a04266185a..cc40a86a18d 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -72,8 +72,8 @@ denorm_ftz_64 = 'nir_is_denorm_flush_to_zero(info->float_controls_execution_mode # opcodes. # # All expression types can have a bit-size specified. For opcodes, this -# looks like "op@32", for variables it is "a@32" or "a@uint32" to specify a -# type and size. In the search half of the expression this indicates that it +# looks like "op@32", for variables it is "a@32" to specify a size. +# In the search half of the expression this indicates that it # should only match that particular bit-size. In the replace half of the # expression this indicates that the constructed value should have that # bit-size. diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c index 3e1e021045a..403e5fc08ae 100644 --- a/src/compiler/nir/nir_search.c +++ b/src/compiler/nir/nir_search.c @@ -71,48 +71,6 @@ static const uint8_t identity_swizzle[NIR_MAX_VEC_COMPONENTS] = { 15, }; -/** - * Check if a source produces a value of the given type. - * - * Used for satisfying 'a@type' constraints. - */ -static bool -src_is_type(nir_src src, nir_alu_type type) -{ - assert(type != nir_type_invalid); - - if (nir_src_is_alu(src)) { - nir_alu_instr *src_alu = nir_def_as_alu(src.ssa); - nir_alu_type output_type = nir_op_infos[src_alu->op].output_type; - - if (type == nir_type_bool) { - switch (src_alu->op) { - case nir_op_iand: - case nir_op_ior: - case nir_op_ixor: - return src_is_type(src_alu->src[0].src, nir_type_bool) && - src_is_type(src_alu->src[1].src, nir_type_bool); - case nir_op_inot: - return src_is_type(src_alu->src[0].src, nir_type_bool); - default: - break; - } - } - - return nir_alu_type_get_base_type(output_type) == type; - } else if (nir_src_is_intrinsic(src)) { - nir_intrinsic_instr *intr = nir_def_as_intrinsic(src.ssa); - - if (type == nir_type_bool) { - return intr->intrinsic == nir_intrinsic_load_front_face || - intr->intrinsic == nir_intrinsic_load_helper_invocation; - } - } - - /* don't know */ - return false; -} - static bool nir_op_matches_search_op(nir_op nop, uint16_t sop) { @@ -281,10 +239,6 @@ match_value(const nir_algebraic_table *table, src, num_components, new_swizzle)) return false; - if (var->type != nir_type_invalid && - !src_is_type(instr->src[src].src, var->type)) - return false; - if (state->variables_seen & (1 << var->variable)) { if (state->variables[var->variable].src.ssa != instr->src[src].src.ssa) return false; diff --git a/src/compiler/nir/nir_search.h b/src/compiler/nir/nir_search.h index 6432b2a041f..4c7683e34e1 100644 --- a/src/compiler/nir/nir_search.h +++ b/src/compiler/nir/nir_search.h @@ -73,18 +73,6 @@ typedef struct { */ bool is_constant : 1; - /** Indicates that the given variable must have a certain type - * - * This is only allowed in search expressions and indicates that the - * given variable is only allowed to match values that come from an ALU - * instruction with the given output type. A type of nir_type_void - * means it can match any type. - * - * Note: A variable that is both constant and has a non-void type will - * never match anything. - */ - nir_alu_type type; - /** Optional table->variable_cond[] fxn ptr index * * This is only allowed in search expressions, and allows additional