diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 7e6136fbe88..75987e3cc58 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1177,13 +1177,13 @@ optimizations.extend([ # The results expecting true, must be marked imprecise. The results # expecting false are fine because NaN compared >= or < anything is false. - (('~fge', 'a(is_not_negative)', 'b(is_not_positive)'), True), - (('fge', 'a(is_not_positive)', 'b(is_gt_zero)'), False), - (('fge', 'a(is_lt_zero)', 'b(is_not_negative)'), False), + (('fge', 'a(is_a_number_not_negative)', 'b(is_a_number_not_positive)'), True), + (('fge', 'a(is_not_positive)', 'b(is_gt_zero)'), False), + (('fge', 'a(is_lt_zero)', 'b(is_not_negative)'), False), - (('flt', 'a(is_not_negative)', 'b(is_not_positive)'), False), - (('~flt', 'a(is_not_positive)', 'b(is_gt_zero)'), True), - (('~flt', 'a(is_lt_zero)', 'b(is_not_negative)'), True), + (('flt', 'a(is_not_negative)', 'b(is_not_positive)'), False), + (('flt', 'a(is_a_number_not_positive)', 'b(is_a_number_gt_zero)'), True), + (('flt', 'a(is_a_number_lt_zero)', 'b(is_a_number_not_negative)'), True), (('ine', 'a(is_not_zero)', 0), True), (('ieq', 'a(is_not_zero)', 0), False), diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h index cae9ef4f0bd..a49b1edaa41 100644 --- a/src/compiler/nir/nir_search_helpers.h +++ b/src/compiler/nir/nir_search_helpers.h @@ -442,6 +442,15 @@ is_ ## r (struct hash_table *ht, const nir_alu_instr *instr, \ { \ const struct ssa_result_range v = nir_analyze_range(ht, instr, src); \ return v.range == r; \ +} \ + \ +static inline bool \ +is_a_number_ ## r (struct hash_table *ht, const nir_alu_instr *instr, \ + unsigned src, UNUSED unsigned num_components, \ + UNUSED const uint8_t *swizzle) \ +{ \ + const struct ssa_result_range v = nir_analyze_range(ht, instr, src); \ + return v.is_a_number && v.range == r; \ } RELATION(lt_zero) @@ -458,6 +467,17 @@ is_not_negative(struct hash_table *ht, const nir_alu_instr *instr, unsigned src, return v.range == ge_zero || v.range == gt_zero || v.range == eq_zero; } +static inline bool +is_a_number_not_negative(struct hash_table *ht, const nir_alu_instr *instr, + unsigned src, UNUSED unsigned num_components, + UNUSED const uint8_t *swizzle) +{ + const struct ssa_result_range v = nir_analyze_range(ht, instr, src); + return v.is_a_number && + (v.range == ge_zero || v.range == gt_zero || v.range == eq_zero); +} + + static inline bool is_not_positive(struct hash_table *ht, const nir_alu_instr *instr, unsigned src, UNUSED unsigned num_components, UNUSED const uint8_t *swizzle) @@ -466,6 +486,16 @@ is_not_positive(struct hash_table *ht, const nir_alu_instr *instr, unsigned src, return v.range == le_zero || v.range == lt_zero || v.range == eq_zero; } +static inline bool +is_a_number_not_positive(struct hash_table *ht, const nir_alu_instr *instr, + unsigned src, UNUSED unsigned num_components, + UNUSED const uint8_t *swizzle) +{ + const struct ssa_result_range v = nir_analyze_range(ht, instr, src); + return v.is_a_number && + (v.range == le_zero || v.range == lt_zero || v.range == eq_zero); +} + static inline bool is_not_zero(struct hash_table *ht, const nir_alu_instr *instr, unsigned src, UNUSED unsigned num_components, UNUSED const uint8_t *swizzle) @@ -474,6 +504,16 @@ is_not_zero(struct hash_table *ht, const nir_alu_instr *instr, unsigned src, return v.range == lt_zero || v.range == gt_zero || v.range == ne_zero; } +static inline bool +is_a_number_not_zero(struct hash_table *ht, const nir_alu_instr *instr, + unsigned src, UNUSED unsigned num_components, + UNUSED const uint8_t *swizzle) +{ + const struct ssa_result_range v = nir_analyze_range(ht, instr, src); + return v.is_a_number && + (v.range == lt_zero || v.range == gt_zero || v.range == ne_zero); +} + static inline bool is_a_number(struct hash_table *ht, const nir_alu_instr *instr, unsigned src, UNUSED unsigned num_components, UNUSED const uint8_t *swizzle)