From 18a0de18344e1bae7afb62b38ff20b74dd130552 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Sat, 22 Mar 2025 07:08:37 +0100 Subject: [PATCH] nir/opt_algebraic: optimize fmax(ffma(a, b, c), 0.0) to fsat Foz-DB Navi21: Totals from 2621 (3.28% of 79789) affected shaders: MaxWaves: 55744 -> 55736 (-0.01%) Instrs: 2840180 -> 2832647 (-0.27%); split: -0.27%, +0.00% CodeSize: 15497364 -> 15464692 (-0.21%); split: -0.21%, +0.00% VGPRs: 138448 -> 138456 (+0.01%) Latency: 22319512 -> 22307018 (-0.06%); split: -0.06%, +0.01% InvThroughput: 5745108 -> 5729197 (-0.28%); split: -0.28%, +0.00% Copies: 110279 -> 110268 (-0.01%); split: -0.04%, +0.03% VALU: 2210578 -> 2203211 (-0.33%); split: -0.33%, +0.00% SALU: 169014 -> 168841 (-0.10%) Reviewed-by: Alyssa Rosenzweig 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 a8c2fba3b07..d3661df81b7 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1031,6 +1031,12 @@ optimizations.extend([ (('fmax', ('fadd(is_used_once)', 'a(is_not_positive)', '#b(is_zero_to_one)'), 0.0), ('fsat', ('fadd', a, b)), '!options->lower_fsat'), + # ffma variants of the pattern above. + (('fmax', ('ffma(is_used_once)', 'a(is_not_positive)', 'b(is_not_negative)', '#c(is_zero_to_one)'), 0.0), + ('fsat', ('ffma', a, b, c)), '!options->lower_fsat'), + (('fmax', ('ffma(is_used_once)', 'a', ('fneg', a), '#b(is_zero_to_one)'), 0.0), + ('fsat', ('ffma', a, ('fneg', a), b)), '!options->lower_fsat'), + (('extract_u8', ('imin', ('imax', a, 0), 0xff), 0), ('imin', ('imax', a, 0), 0xff)), # The ior versions are exact because fmin and fmax will always pick a