From 1d5c42528b00929fef2c45795759826ff566e543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 11 Mar 2025 22:40:30 -0400 Subject: [PATCH] nir/opt_algebraic: lower 16-bit imul_high & umul_high MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tested-by: Dieter Nützel Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/amd/common/nir/ac_nir.c | 1 + src/compiler/nir/nir_opt_algebraic.py | 3 +++ src/compiler/nir/nir_shader_compiler_options.h | 1 + 3 files changed, 5 insertions(+) diff --git a/src/amd/common/nir/ac_nir.c b/src/amd/common/nir/ac_nir.c index 8cdc613b07d..17a255b0521 100644 --- a/src/amd/common/nir/ac_nir.c +++ b/src/amd/common/nir/ac_nir.c @@ -57,6 +57,7 @@ void ac_nir_set_options(struct radeon_info *info, bool use_llvm, options->lower_unpack_unorm_4x8 = true; options->lower_unpack_half_2x16 = true; options->lower_fpow = true; + options->lower_mul_high16 = true; options->lower_mul_2x32_64 = true; options->lower_iadd_sat = info->gfx_level <= GFX8; options->lower_hadd = true; diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index a6b659aea73..9fe13495122 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -2671,6 +2671,9 @@ optimizations.extend([ (('imul24', a, '#b@32(is_pos_power_of_two)'), ('ishl', a, ('find_lsb', b)), '!options->lower_bitops'), (('imul24', a, '#b@32(is_neg_power_of_two)'), ('ineg', ('ishl', a, ('find_lsb', ('iabs', b)))), '!options->lower_bitops'), (('imul24', a, 0), (0)), + + (('imul_high@16', a, b), ('i2i16', ('ishr', ('imul24_relaxed', ('i2i32', a), ('i2i32', b)), 16)), 'options->lower_mul_high16'), + (('umul_high@16', a, b), ('u2u16', ('ushr', ('umul24_relaxed', ('u2u32', a), ('u2u32', b)), 16)), 'options->lower_mul_high16'), ]) for bit_size in [8, 16, 32, 64]: diff --git a/src/compiler/nir/nir_shader_compiler_options.h b/src/compiler/nir/nir_shader_compiler_options.h index aa972f7a753..483031ee6ca 100644 --- a/src/compiler/nir/nir_shader_compiler_options.h +++ b/src/compiler/nir/nir_shader_compiler_options.h @@ -243,6 +243,7 @@ typedef struct nir_shader_compiler_options { bool lower_usub_borrow; /** Lowers imul_high/umul_high to 16-bit multiplies and carry operations. */ bool lower_mul_high; + bool lower_mul_high16; /** lowers fneg to fmul(x, -1.0). Driver must call nir_opt_algebraic_late() */ bool lower_fneg; /** lowers ineg to isub. Driver must call nir_opt_algebraic_late(). */