From f2fbba7920934dc94c907c069f73ad6513d91432 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Fri, 1 Oct 2021 11:27:00 +0100 Subject: [PATCH] nir/algebraic: optimize open-coded fmulz/ffmaz MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This pattern will be found in future versions of D3D9 DXVK. Signed-off-by: Rhys Perry Reviewed-by: Timur Kristóf Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 147e0dd345d..075fc1b485e 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -238,6 +238,19 @@ optimizations = [ (('sudot_4x8_iadd_sat', '#a', '#b', 'c(is_not_const)'), ('iadd_sat', ('sudot_4x8_iadd', a, b, 0), c), '!options->lower_iadd_sat'), (('sdot_2x16_iadd_sat', '#a', '#b', 'c(is_not_const)'), ('iadd_sat', ('sdot_2x16_iadd', a, b, 0), c), '!options->lower_iadd_sat'), (('udot_2x16_uadd_sat', '#a', '#b', 'c(is_not_const)'), ('uadd_sat', ('udot_2x16_uadd', a, b, 0), c), '!options->lower_uadd_sat'), + + # Optimize open-coded fmulz. + # (b==0.0 ? 0.0 : a) * (a==0.0 ? 0.0 : b) -> fmulz(a, b) + (('fmul@32', ('bcsel', ignore_exact('feq', b, 0.0), 0.0, a), ('bcsel', ignore_exact('feq', a, 0.0), 0.0, b)), + ('fmulz', a, b), 'options->has_fmulz && !'+signed_zero_inf_nan_preserve_32), + (('fmul@32', a, ('bcsel', ignore_exact('feq', a, 0.0), 0.0, '#b(is_not_const_zero)')), + ('fmulz', a, b), 'options->has_fmulz && !'+signed_zero_inf_nan_preserve_32), + + # ffma(b==0.0 ? 0.0 : a, a==0.0 ? 0.0 : b, c) -> ffmaz(a, b, c) + (('ffma@32', ('bcsel', ignore_exact('feq', b, 0.0), 0.0, a), ('bcsel', ignore_exact('feq', a, 0.0), 0.0, b), c), + ('ffmaz', a, b, c), 'options->has_fmulz && !'+signed_zero_inf_nan_preserve_32), + (('ffma@32', a, ('bcsel', ignore_exact('feq', a, 0.0), 0.0, '#b(is_not_const_zero)'), c), + ('ffmaz', a, b, c), 'options->has_fmulz && !'+signed_zero_inf_nan_preserve_32), ] # Shorthand for the expansion of just the dot product part of the [iu]dp4a