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 <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40389>
This commit is contained in:
Georg Lehmann 2026-03-13 09:49:00 +01:00 committed by Marge Bot
parent d77c2a1ece
commit 4d176c8ea5

View file

@ -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'),