From 4c3ad4d06588dcc8f5c4d9e27c746055a013f358 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Tue, 26 Jan 2021 14:25:32 +0100 Subject: [PATCH] nir/algebraic: mark more optimization with fsat(NaN) as inexact These optimizations are duplicated from the main optimization table to the late one... And I missed some in the original fix. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3368 Fixes: bc123c396a9 ("nir/algebraic: mark some optimizations with fsat(NaN) as inexact") Signed-off-by: Samuel Pitoiset Reviewed-by: Rhys Perry Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index ed7826da63b..db8437987b7 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -377,8 +377,12 @@ optimizations.extend([ (('fneu', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fneu', a, b)), (('fge', ('fsat(is_used_once)', a), 1.0), ('fge', a, 1.0)), - (('flt', ('fsat(is_used_once)', a), 1.0), ('flt', a, 1.0)), - (('fge', 0.0, ('fsat(is_used_once)', a)), ('fge', 0.0, a)), + # flt(fsat(a), 1.0) is inexact because it returns True if a is NaN + # (fsat(NaN) is 0), while flt(a, 1.0) always returns FALSE. + (('~flt', ('fsat(is_used_once)', a), 1.0), ('flt', a, 1.0)), + # fge(0.0, fsat(a)) is inexact because it returns True if a is NaN + # (fsat(NaN) is 0), while fge(0.0, a) always returns FALSE. + (('~fge', 0.0, ('fsat(is_used_once)', a)), ('fge', 0.0, a)), (('flt', 0.0, ('fsat(is_used_once)', a)), ('flt', 0.0, a)), # 0.0 >= b2f(a) @@ -2139,10 +2143,15 @@ late_optimizations = [ # new patterns like these. The patterns that compare with zero are removed # because they are unlikely to be created in by anything in # late_optimizations. - (('flt', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('flt', a, b)), + + # flt(fsat(a), b > 0 && b < 1) is inexact if a is NaN (fsat(NaN) is 0) + # because it returns True while flt(a, b) always returns False. + (('~flt', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('flt', a, b)), (('flt', '#b(is_gt_0_and_lt_1)', ('fsat(is_used_once)', a)), ('flt', b, a)), (('fge', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fge', a, b)), - (('fge', '#b(is_gt_0_and_lt_1)', ('fsat(is_used_once)', a)), ('fge', b, a)), + # fge(b > 0 && b < 1, fsat(a)) is inexact if a is NaN (fsat(NaN) is 0) + # because it returns True while fge(b, a) always returns False. + (('~fge', '#b(is_gt_0_and_lt_1)', ('fsat(is_used_once)', a)), ('fge', b, a)), (('feq', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('feq', a, b)), (('fneu', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fneu', a, b)),