From 22afe834730a2d0ae8b54c309cf23993e8896fd3 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Fri, 1 Aug 2025 21:16:40 +0200 Subject: [PATCH] nir/opt_algebraic: remove fneg around fmin/fmax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Foz-DB Navi21: Totals from 282 (0.35% of 80255) affected shaders: Instrs: 310515 -> 309755 (-0.24%) CodeSize: 1721236 -> 1714540 (-0.39%) Latency: 1366446 -> 1365141 (-0.10%); split: -0.10%, +0.00% InvThroughput: 352528 -> 351097 (-0.41%); split: -0.41%, +0.00% Copies: 24623 -> 24630 (+0.03%) VALU: 231716 -> 230951 (-0.33%) SALU: 28774 -> 28779 (+0.02%) Reviewed-by: Marek Olšák Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index df1fa50c519..004cb4a9173 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -918,6 +918,12 @@ optimizations.extend([ (('fmin(nsz)', 'a(is_a_number_not_positive)', 'b(is_not_negative)'), ('fmul', a, 1.0)), (('fmax', 'a(is_a_number_not_negative)', 'b(is_lt_zero)'), ('fmul', a, 1.0)), (('fmin', 'a(is_a_number_not_positive)', 'b(is_gt_zero)'), ('fmul', a, 1.0)), + (('fneg', ('fmax(is_used_once)', ('fneg', a), ('fneg', b))), ('fmin', a, b)), + (('fneg', ('fmin(is_used_once)', ('fneg', a), ('fneg', b))), ('fmax', a, b)), + (('fneg', ('fmax(is_used_once)', ('fneg', a), '#b')), ('fmin', a, ('fneg', b))), + (('fneg', ('fmin(is_used_once)', ('fneg', a), '#b')), ('fmax', a, ('fneg', b))), + (('fmin(nsz)', a, '#b(is_negative_zero)'), ('fmin', a, 0.0)), + (('fmax(nsz)', a, '#b(is_negative_zero)'), ('fmax', a, 0.0)), ]) for op in ['ine', 'ieq', 'ilt', 'ige', 'ult', 'uge', 'bitz', 'bitnz',