From: Samuel Pitoiset Date: Mon, 31 Aug 2020 14:08:55 +0000 (+0200) Subject: nir/algebraic: mark some optimizations with fsat(NaN) as inexact X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bc123c396a99b2f6ff845792374d6a8d5de5d15e;p=mesa.git nir/algebraic: mark some optimizations with fsat(NaN) as inexact If a is Nan, fsat(NaN) is expected to be 0 and some optimizations should be marked as inexact. Fixes a GPU hang with Death Stranding and RADV/ACO (RADV/LLVM isn't affected because it lowers fsat). No fossils-db change. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3368 Cc: mesa-stable Signed-off-by: Samuel Pitoiset Reviewed-by: Alyssa Rosenzweig Reviewed-by: Bas Nieuwenhuizen Reviewed-by: Rhys Perry Part-of: --- diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 2fe41d02deb..d775a23fcee 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -329,10 +329,14 @@ optimizations.extend([ (('fneu', ('fneg', a), -1.0), ('fneu', 1.0, a)), (('feq', -1.0, ('fneg', a)), ('feq', a, 1.0)), - (('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)), @@ -1913,7 +1917,9 @@ late_optimizations = [ (('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)), + # 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', ('fmin(is_used_once)', ('fadd(is_used_once)', a, b), ('fadd', c, d)), 0.0), ('iand', ('fge', a, ('fneg', b)), ('fge', c, ('fneg', d)))),