From 4d176c8ea52453841b9767597d40e116d0befffd Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Fri, 13 Mar 2026 09:49:00 +0100 Subject: [PATCH] nir/opt_algebraic: turn fabs(a) into fneg(a) if a is not positive fneg is usually more optimizable. Foz-DB Navi48: Totals from 214 (0.19% of 114655) affected shaders: Instrs: 694279 -> 694155 (-0.02%); split: -0.02%, +0.00% CodeSize: 3749268 -> 3748024 (-0.03%); split: -0.03%, +0.00% VGPRs: 18252 -> 18264 (+0.07%) Latency: 5453691 -> 5453503 (-0.00%); split: -0.00%, +0.00% InvThroughput: 1024436 -> 1024314 (-0.01%); split: -0.01%, +0.00% VALU: 453136 -> 453041 (-0.02%); split: -0.02%, +0.00% Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 78cbdb8b498..7df3a4a1c31 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1910,6 +1910,7 @@ optimizations.extend([ (('ffract(nnan)', 'a(is_integral)'), 0.0), (('ffract', ('ffract', a)), ('ffract', a)), (('fabs', 'a(is_not_negative)'), ('fcanonicalize', a)), + (('fabs(nsz)', 'a(is_not_positive)'), ('fneg', a)), (('fsat', 'a(is_not_positive)'), 0.0), (('fmin(nsz)', 'a(is_a_number_not_negative)', 1.0), ('fsat', a), '!options->lower_fsat'),