diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 4b370a23d50..7abe6a6903b 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1055,10 +1055,11 @@ optimizations.extend([ # fmin(0.0, b)) while the right one is "b", so this optimization is not NaN correct. (('fmin(nsz)', ('fsat(nnan)', a), '#b(is_zero_to_one)'), ('fsat', ('fmin', a, b))), - # If a >= 0 ... 1 + a >= 1 ... so fsat(1 + a) = 1 - # But 1 + NaN is NaN and fsat(NaN) = 0. - (('fsat(nnan)', ('fadd', 1.0, 'a(is_not_negative)')), 1.0), - (('fsat', ('fadd', 1.0, 'a(is_a_number_not_negative)')), 1.0), + (('fsat(nnan)', 'a(is_ge_pos_one)'), 1.0), + (('fsat', 'a(is_a_number_ge_pos_one)'), 1.0), + + (('fsat(nnan,nsz)', 'a(is_zero_to_one)'), ('fcanonicalize', a)), + (('fsat(nsz)', 'a(is_a_number_zero_to_one)'), ('fcanonicalize', a)), # Let constant folding do its job. This can have emergent behaviour. (('fneg', ('bcsel(is_used_once)', a, '#b', '#c')), ('bcsel', a, ('fneg', b), ('fneg', c))), diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h index 10aac18312f..c6e20d78892 100644 --- a/src/compiler/nir/nir_search_helpers.h +++ b/src/compiler/nir/nir_search_helpers.h @@ -875,6 +875,7 @@ RELATION_AND_NUM(not_zero, FP_CLASS_ANY_ZERO) RELATION_AND_NUM(zero_to_one, FP_CLASS_ANY_NEG | FP_CLASS_GT_POS_ONE | FP_CLASS_POS_INF) RELATION_AND_NUM(le_pos_one, FP_CLASS_GT_POS_ONE | FP_CLASS_POS_INF) RELATION_AND_NUM(gt_0_and_lt_1, FP_CLASS_ANY_NEG | FP_CLASS_ANY_ZERO | FP_CLASS_POS_ONE | FP_CLASS_GT_POS_ONE | FP_CLASS_POS_INF) +RELATION_AND_NUM(ge_pos_one, FP_CLASS_ANY_NEG | FP_CLASS_ANY_ZERO | FP_CLASS_GT_ZERO_LT_POS_ONE) RELATION(a_number, FP_CLASS_NAN) RELATION(finite, FP_CLASS_ANY_INF | FP_CLASS_NAN) RELATION(finite_not_zero, FP_CLASS_ANY_INF | FP_CLASS_NAN | FP_CLASS_ANY_ZERO)