From 87592234984cfff421e3fa6f67ed792251825e0b Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Fri, 21 Feb 2025 15:25:06 +0100 Subject: [PATCH] nir/opt_algebraic: optimize b2i/b2f comparision with non 0/1 constants Foz-DB Navi21: Totals from 28 (0.04% of 79789) affected shaders: MaxWaves: 732 -> 728 (-0.55%) Instrs: 23425 -> 22559 (-3.70%) CodeSize: 137740 -> 132292 (-3.96%) VGPRs: 1128 -> 1144 (+1.42%) Latency: 94604 -> 92423 (-2.31%) InvThroughput: 19166 -> 18814 (-1.84%); split: -2.38%, +0.54% VClause: 429 -> 423 (-1.40%) SClause: 937 -> 926 (-1.17%) Copies: 1199 -> 914 (-23.77%); split: -24.52%, +0.75% Branches: 451 -> 421 (-6.65%) PreSGPRs: 1043 -> 996 (-4.51%) PreVGPRs: 992 -> 973 (-1.92%); split: -3.53%, +1.61% VALU: 17566 -> 16865 (-3.99%) SALU: 1254 -> 1157 (-7.74%) VMEM: 619 -> 609 (-1.62%) Reviewed-by: Ian Romanick 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 4763cb31d2a..890899a962e 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -3268,6 +3268,8 @@ for b2t, xne, xeq, zero, one in (('b2i', 'ine', 'ieq', 0, 1), ((xeq, (b2t, 'a@1'), one), a), ((xne, (b2t, 'a@1'), zero), a), ((xne, (b2t, 'a@1'), one), ('inot', a)), + ((xeq, (b2t, 'a@1'), '#b'), ('bcsel', (xeq, b, zero), ('inot', a), ('bcsel', (xeq, b, one), a, False))), + ((xne, (b2t, 'a@1'), '#b'), ('bcsel', (xeq, b, zero), a, ('bcsel', (xeq, b, one), ('inot', a), True))), ] # This section contains "late" optimizations that should be run before