From 7505be3497cba09bb0a3e3787aeb107f32eeeee2 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Tue, 4 Oct 2022 15:38:58 +0200 Subject: [PATCH] nir/opt_algebraic: Add an option to lower uclz. Signed-off-by: Georg Lehmann Reviewed-by: Ian Romanick Reviewed-by: Rhys Perry Part-of: --- src/compiler/nir/nir.h | 5 +++++ src/compiler/nir/nir_opt_algebraic.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index c7372301f4a..a460faad950 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3507,6 +3507,11 @@ typedef struct nir_shader_compiler_options { */ bool lower_mul_32x16; + /** + * Set if uclz should be lowered to find_msb_rev. + */ + bool lower_uclz; + /** * Should IO be re-vectorized? Some scalar ISAs still operate on vec4's * for IO purposes and would prefer loads/stores be vectorized. diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 39ca3be927b..b8209f732d8 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1889,6 +1889,8 @@ optimizations.extend([ ('ufind_msb_rev', 'value')), 'options->lower_find_msb_to_reverse'), + (('uclz', a), ('umin', 32, ('ufind_msb_rev', a)), 'options->lower_uclz'), + (('find_lsb', 'value'), ('ufind_msb', ('iand', 'value', ('ineg', 'value'))), 'options->lower_find_lsb'),