From 3b06824e4c489a6e7f6f1ba1a89b1878d40dc23e Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Fri, 22 Aug 2025 17:56:35 +0200 Subject: [PATCH] nir/opt_algebraic: optimize some post peephole select patterns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Foz-DB GFX1201: Totals from 208 (0.26% of 80287) affected shaders: Instrs: 427684 -> 426834 (-0.20%); split: -0.22%, +0.02% CodeSize: 2232616 -> 2228816 (-0.17%); split: -0.20%, +0.03% Latency: 3993934 -> 3992726 (-0.03%); split: -0.04%, +0.01% InvThroughput: 569055 -> 568622 (-0.08%); split: -0.09%, +0.01% SClause: 12932 -> 12927 (-0.04%) Copies: 22567 -> 22604 (+0.16%); split: -0.47%, +0.63% Branches: 7671 -> 7658 (-0.17%) VALU: 222047 -> 221625 (-0.19%) SALU: 83954 -> 83815 (-0.17%); split: -0.29%, +0.13% Reviewed-by: Marek Olšák Reviewed-by: Rhys Perry Acked-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index de71167024a..7aae5cf4943 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -731,6 +731,13 @@ optimizations.extend([ # 0 < fsat(NaN) -> 0 < 0 -> false, and 0 < NaN -> false. (('flt', 0.0, ('fsat(is_used_once)', a)), ('flt', 0.0, a)), + (('bcsel(is_only_used_as_float)', ('feq', a, 'b(is_not_zero)'), b, a), a), + (('bcsel(is_only_used_as_float)', ('fneu', a, 'b(is_not_zero)'), a, b), a), + (('bcsel', ignore_exact('feq', a, 0), 0, ('fsat', ('fmul', a, 'b(is_a_number)'))), ('fsat!', ('fmul', a, b))), + (('bcsel', ignore_exact('fneu', a, 0), ('fsat', ('fmul', a, 'b(is_a_number)')), 0), ('fsat!', ('fmul', a, b))), + (('bcsel', ignore_exact('feq', a, 0), b, ('fadd', a, 'b(is_not_zero)')), ('fadd', a, b)), + (('bcsel', ignore_exact('fneu', a, 0), ('fadd', a, 'b(is_not_zero)'), b), ('fadd', a, b)), + # 0.0 >= b2f(a) # b2f(a) <= 0.0 # b2f(a) == 0.0 because b2f(a) can only be 0 or 1