From e0cebac14f21af2197b95ae52c113d8a80f388c6 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Fri, 21 Feb 2025 17:23:04 +0100 Subject: [PATCH] nir/opt_algebraic: optimize b2f(a != 0) * a Just D3D9 things. Foz-DB Navi21: Totals from 137 (0.17% of 79377) affected shaders: MaxWaves: 3366 -> 3370 (+0.12%); split: +0.24%, -0.12% Instrs: 76462 -> 72091 (-5.72%) CodeSize: 411584 -> 380792 (-7.48%) Latency: 279472 -> 275505 (-1.42%); split: -2.01%, +0.59% InvThroughput: 71311 -> 65369 (-8.33%) VClause: 1587 -> 1612 (+1.58%); split: -1.01%, +2.58% SClause: 1111 -> 1105 (-0.54%); split: -1.08%, +0.54% Copies: 5621 -> 5602 (-0.34%); split: -1.39%, +1.05% PreSGPRs: 5266 -> 5241 (-0.47%); split: -0.51%, +0.04% PreVGPRs: 4249 -> 4236 (-0.31%); split: -0.35%, +0.05% VALU: 50049 -> 45901 (-8.29%) SALU: 8948 -> 8818 (-1.45%) Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 1a54969afc5..5fe5e2ec96e 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1502,6 +1502,8 @@ optimizations.extend([ (('ior', ('b2i', 'a@1'), ('b2i', 'b@1')), ('b2i', ('ior', a, b))), (('fmul', ('b2f', 'a@1'), ('b2f', 'b@1')), ('b2f', ('iand', a, b))), (('ffma', ('b2f', 'a@1'), ('b2f', 'b@1'), c), ('fadd', ('b2f', ('iand', a, b)), c)), + (('fmul', ('b2f', ('fneu', a, 0)), a), ('fmul', 1.0, a)), + (('ffma', ('b2f', ('fneu', a, 0)), a, b), ('fadd', a, b)), (('fsat', ('fadd', ('b2f', 'a@1'), ('b2f', 'b@1'))), ('b2f', ('ior', a, b))), (('iand', 'a@bool16', 1.0), ('b2f', a)), (('iand', 'a@bool32', 1.0), ('b2f', a)),