diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/nir/nir_opt_algebraic.py | 27 | ||||
-rw-r--r-- | src/compiler/nir/nir_search_helpers.h | 30 |
2 files changed, 57 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 5fc6fd80de4..79058c06b97 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -213,6 +213,18 @@ optimizations = [ (('fne', ('fneg', a), -1.0), ('fne', 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', '#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)), + (('feq', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('feq', a, b)), + (('fne', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fne', 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', 0.0, ('fsat(is_used_once)', a)), ('flt', 0.0, a)), + # 0.0 >= b2f(a) # b2f(a) <= 0.0 # b2f(a) == 0.0 because b2f(a) can only be 0 or 1 @@ -1136,6 +1148,21 @@ late_optimizations = [ # optimization loop can prevent other optimizations. (('fneg', ('fneg', a)), a), + # These are duplicated from the main optimizations table. The late + # patterns that rearrange expressions like x - .5 < 0 to x < .5 can create + # 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', '#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)), + (('feq', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('feq', a, b)), + (('fne', ('fsat(is_used_once)', a), '#b(is_gt_0_and_lt_1)'), ('fne', 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', ('fmin(is_used_once)', ('fadd(is_used_once)', a, b), ('fadd', c, d)), 0.0), ('iand', ('fge', a, ('fneg', b)), ('fge', c, ('fneg', d)))), (('flt', ('fneg', a), ('fneg', b)), ('flt', b, a)), diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h index dd220dfdffd..9e03c610ece 100644 --- a/src/compiler/nir/nir_search_helpers.h +++ b/src/compiler/nir/nir_search_helpers.h @@ -109,6 +109,36 @@ is_zero_to_one(nir_alu_instr *instr, unsigned src, unsigned num_components, return true; } +/** + * Exclusive compare with (0, 1). + * + * This differs from \c is_zero_to_one because that function tests 0 <= src <= + * 1 while this function tests 0 < src < 1. + */ +static inline bool +is_gt_0_and_lt_1(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++) { + switch (nir_op_infos[instr->op].input_types[src]) { + case nir_type_float: { + double val = nir_src_comp_as_float(instr->src[src].src, swizzle[i]); + if (isnan(val) || val <= 0.0f || val >= 1.0f) + return false; + break; + } + default: + return false; + } + } + + return true; +} + static inline bool is_not_const_zero(nir_alu_instr *instr, unsigned src, unsigned num_components, const uint8_t *swizzle) |