Commit 07cd30ca authored by Samuel Pitoiset's avatar Samuel Pitoiset Committed by Marge Bot
Browse files

nir/opt_algebraic: optimize fmax(-fmin(b, a), b) -> fmax(b, -a)



Found with Cyberpunk 2077.

fossils-db (GFX10.3):
Totals from 128 (2.34% of 5465) affected shaders:
CodeSize: 769720 -> 767656 (-0.27%); split: -0.27%, +0.00%
Instrs: 145748 -> 145229 (-0.36%)
Signed-off-by: Samuel Pitoiset's avatarSamuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Daniel Schürmann's avatarDaniel Schürmann <daniel@schuermann.dev>
Part-of: <!11604>
parent 0cddfba3
Pipeline #387003 waiting for manual action with stages
......@@ -652,6 +652,11 @@ optimizations.extend([
# fmin(0.0, b)) while the right one is "b", so this optimization is inexact.
(('~fmin', ('fsat', a), '#b(is_zero_to_one)'), ('fsat', ('fmin', a, b))),
# max(-min(b, a), b) -> max(b, -a)
# min(-max(b, a), b) -> min(-b, -a)
(('fmax', ('fneg', ('fmin', b, a)), b), ('fmax', b, ('fneg', a))),
(('fmin', ('fneg', ('fmax', b, a)), b), ('fmin', ('fneg', b), ('fneg', a))),
# If a in [0,b] then b-a is also in [0,b]. Since b in [0,1], max(b-a, 0) =
# fsat(b-a).
#
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment