From 8d90b13954f56d30204f1372874c42f96e329be1 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 18 Feb 2022 16:59:03 -0800 Subject: [PATCH] nir/algebraic: Catch some kinds of copy-and-paste bugs in algebraic patterns MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit A later commit adds a pattern (('umin', ('iand', a, '#b(is_pos_power_of_two)'), ('iand', c, '#b(is_pos_power_of_two)')), ('iand', ('iand', a, b), ('iand', c, b))), When I originally made that pattern, I copied and pasted the search to the replacement as (('umin', ('iand', a, '#b(is_pos_power_of_two)'), ('iand', c, '#b(is_pos_power_of_two)')), ('iand', ('iand', a, '#b(is_pos_power_of_two)'), ('iand', c, '#b(is_pos_power_of_two)'))), The caused the variables in the replacement to be marked is_constant, and that resulted in an assertion failure deep inside nir_search. src/compiler/nir/nir_search.c:530: construct_value: Assertion `!var->is_constant' failed. These extra validation rules catch this kind of error at compile time rather than at run time. Reviewed-by: Alyssa Rosenzweig Reviewed-by: Jason Ekstrand Acked-by: Jesse Natalie Tested-by: Daniel Schürmann Part-of: --- src/compiler/nir/nir_algebraic.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 2adc4d0..4a2e438 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -739,6 +739,17 @@ class BitSizeValidator(object): if isinstance(val, Expression): for src in val.sources: self.validate_replace(src, search) + elif isinstance(val, Variable): + # These catch problems when someone copies and pastes the search + # into the replacement. + assert not val.is_constant, \ + 'Replacement variables must not be marked constant.' + + 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 -- 2.7.4