diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index e7957f730c6..d6919950dd5 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -608,6 +608,12 @@ optimizations.extend([ (('fge', -1.0, ('fneg', a)), ('fge', a, 1.0)), (('fneu', ('fneg', a), -1.0), ('fneu', 1.0, a)), (('feq', -1.0, ('fneg', a)), ('feq', a, 1.0)), + (('flt', a, '#b(is_negative_zero)'), ('flt', a, 0.0)), + (('flt', '#b(is_negative_zero)', a), ('flt', 0.0, a)), + (('fge', a, '#b(is_negative_zero)'), ('fge', a, 0.0)), + (('fge', '#b(is_negative_zero)', a), ('fge', 0.0, a)), + (('fneu', a, '#b(is_negative_zero)'), ('fneu', 0.0, a)), + (('feq', '#b(is_negative_zero)', a), ('feq', a, 0.0)), (('ieq', ('ineg', a), 0), ('ieq', a, 0)), (('ine', ('ineg', a), 0), ('ine', a, 0)), diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h index 6a1740fbae8..44ede8b3ee6 100644 --- a/src/compiler/nir/nir_search_helpers.h +++ b/src/compiler/nir/nir_search_helpers.h @@ -29,6 +29,7 @@ #include #include "util/bitscan.h" +#include "util/u_math.h" #include "nir.h" #include "nir_range_analysis.h" @@ -127,6 +128,24 @@ is_nan(UNUSED struct hash_table *ht, const nir_alu_instr *instr, return true; } +static inline bool +is_negative_zero(UNUSED struct hash_table *ht, const nir_alu_instr *instr, + unsigned src, unsigned num_components, const uint8_t *swizzle) +{ + /* only constant srcs: */ + if (!nir_src_is_const(instr->src[src].src)) + return false; + + for (unsigned i = 0; i < num_components; i++) { + union di tmp; + tmp.d = nir_src_comp_as_float(instr->src[src].src, swizzle[i]); + if (tmp.ui != 0x8000000000000000ull) + return false; + } + + return true; +} + static inline bool is_any_comp_nan(UNUSED struct hash_table *ht, const nir_alu_instr *instr, unsigned src, unsigned num_components, const uint8_t *swizzle)