From 2d6f48f6efd0cf9b9900d030aa1b571a2e22a4e1 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 24 Oct 2022 13:26:31 -0700 Subject: [PATCH] nir/algebraic: Do not generate 8- or 16-bit find_msb The next commit will add validation to restrict this instruction (and others) to only 32-bit or 64-bit sources. Reviewed-by: Kenneth Graunke Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 4ebd577c203..2a58f914922 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1809,6 +1809,8 @@ optimizations.extend([ (('bcsel', ('ine', 'a@32', 0), ('iadd', 31, ('ineg', ('ufind_msb_rev', a))), ('ufind_msb_rev', a)), ('ufind_msb', a), '!options->lower_find_msb_to_reverse'), (('bcsel', ('ieq', 'a@32', 0), ('ufind_msb_rev', a), ('iadd', 31, ('ineg', ('ufind_msb_rev', a)))), ('ufind_msb', a), '!options->lower_find_msb_to_reverse'), + # This is safe. Both ufind_msb_rev and bitfield_reverse can only have + # 32-bit sources, so the transformation can only generate correct NIR. (('find_lsb', ('bitfield_reverse', a)), ('ufind_msb_rev', a), 'options->has_find_msb_rev'), (('ufind_msb_rev', ('bitfield_reverse', a)), ('find_lsb', a), '!options->lower_find_lsb'), @@ -2047,10 +2049,14 @@ optimizations.extend([ (('uclz', a), ('umin', 32, ('ufind_msb_rev', a)), 'options->lower_uclz'), - (('find_lsb', 'value'), + (('find_lsb', 'value@64'), ('ufind_msb', ('iand', 'value', ('ineg', 'value'))), 'options->lower_find_lsb'), + (('find_lsb', 'value'), + ('ufind_msb', ('u2u32', ('iand', 'value', ('ineg', 'value')))), + 'options->lower_find_lsb'), + (('extract_i8', a, 'b@32'), ('ishr', ('ishl', a, ('imul', ('isub', 3, b), 8)), 24), 'options->lower_extract_byte'),