From fd22c48b2ac8ca010d3562f3c935ffff0e5bcac5 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Tue, 10 Feb 2026 14:46:42 +0000 Subject: [PATCH] nir/algebraic: remove ignore_exact This was used because the exact bit meant something different for comparisons than it did for the replacement expression, but that isn't the case anymore. Signed-off-by: Rhys Perry Reviewed-by: Georg Lehmann Part-of: --- src/compiler/nir/nir_algebraic.py | 2 -- src/compiler/nir/nir_opt_algebraic.py | 24 +++++++++---------- src/compiler/nir/nir_search.c | 6 ++--- src/compiler/nir/nir_search.h | 3 --- .../r300/compiler/r300_nir_algebraic.py | 16 ++++++------- 5 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 9fc4af642a6..77391c5e81b 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -208,7 +208,6 @@ class Value(object): % elif isinstance(val, Expression): ${val.fp_math_ctrl_exclude()}, ${val.fp_math_ctrl_add()}, - ${'true' if val.ignore_exact else 'false'}, ${'true' if len(val.sources) > 1 and isinstance(val.sources[1], Constant) else 'false'}, ${val.swizzle}, ${val.c_opcode()}, @@ -403,7 +402,6 @@ class Expression(Value): self.nnan = cond.pop('nnan', False) self.ninf = cond.pop('ninf', False) self.contract = cond.pop('contract', False) or fp_ctrl == ForceFpCtrl.Contract - self.ignore_exact = cond.pop('ignore_exact', False) self.preserve_nan_inf = cond.pop('preserve_nan_inf', False) self.preserve_sz = cond.pop('preserve_sz', False) if cond.pop('preserve_nan_inf_sz', False): diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 09fae90b309..2e2ea29c075 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -364,13 +364,13 @@ optimizations += [ # Optimize open-coded fmulz. # (b==0.0 ? 0.0 : a) * (a==0.0 ? 0.0 : b) -> fmulz(a, b) - *add_fabs_fneg((('fmul@32(nsz)', ('bcsel', ('feq(ignore_exact)', b, 0.0), 0.0, 'ma'), ('bcsel', ('feq(ignore_exact)', a, 0.0), 0.0, 'mb')), + *add_fabs_fneg((('fmul@32(nsz)', ('bcsel', ('feq', b, 0.0), 0.0, 'ma'), ('bcsel', ('feq', a, 0.0), 0.0, 'mb')), ('fmulz', 'ma', 'mb'), has_fmulz), {'ma' : a, 'mb' : b}), # (b!=0.0 ? a : 0.0) * (a==0.0 ? 0.0 : b) -> fmulz(a, b) - *add_fabs_fneg((('fmul@32(nsz)', ('bcsel', ('fneu(ignore_exact)', b, 0.0), 'ma', 0.0), ('bcsel', ('feq(ignore_exact)', a, 0.0), 0.0, 'mb')), + *add_fabs_fneg((('fmul@32(nsz)', ('bcsel', ('fneu', b, 0.0), 'ma', 0.0), ('bcsel', ('feq', a, 0.0), 0.0, 'mb')), ('fmulz', 'ma', 'mb'), has_fmulz), {'ma' : a, 'mb' : b}), # (b!=0.0 ? a : 0.0) * (a!=0.0 ? b : 0.0) -> fmulz(a, b) - *add_fabs_fneg((('fmul@32(nsz)', ('bcsel', ('fneu(ignore_exact)', b, 0.0), 'ma', 0.0), ('bcsel', ('fneu(ignore_exact)', a, 0.0), 'mb', 0.0)), + *add_fabs_fneg((('fmul@32(nsz)', ('bcsel', ('fneu', b, 0.0), 'ma', 0.0), ('bcsel', ('fneu', a, 0.0), 'mb', 0.0)), ('fmulz', 'ma', 'mb'), has_fmulz), {'ma' : a, 'mb' : b}), # (min(abs(a), abs(b)) == 0.0 ? 0.0 : a * b) -> fmulz(a,b) @@ -378,20 +378,20 @@ optimizations += [ ('fmulz', 'ma', 'mb'), has_fmulz), {'ma': a, 'mb': b}), # a * (a == 0.0 ? 0.0 : b(is_non_const_zero)) - *add_fabs_fneg((('fmul@32(nsz)', 'ma', ('bcsel', ('feq(ignore_exact)', a, 0.0), 0.0, '#b(is_not_const_zero)')), + *add_fabs_fneg((('fmul@32(nsz)', 'ma', ('bcsel', ('feq', a, 0.0), 0.0, '#b(is_not_const_zero)')), ('fmulz', 'ma', b), has_fmulz), {'ma' : a}), # ffma(b==0.0 ? 0.0 : a, a==0.0 ? 0.0 : b, c) -> ffmaz(a, b, c) - *add_fabs_fneg((('ffma@32(nsz)', ('bcsel', ('feq(ignore_exact)', b, 0.0), 0.0, 'ma'), ('bcsel', ('feq(ignore_exact)', a, 0.0), 0.0, 'mb'), c), + *add_fabs_fneg((('ffma@32(nsz)', ('bcsel', ('feq', b, 0.0), 0.0, 'ma'), ('bcsel', ('feq', a, 0.0), 0.0, 'mb'), c), ('ffmaz', 'ma', 'mb', c), has_fmulz), {'ma' : a, 'mb' : b}), - *add_fabs_fneg((('ffma@32(nsz)', 'ma', ('bcsel', ('feq(ignore_exact)', a, 0.0), 0.0, '#b(is_not_const_zero)'), c), + *add_fabs_fneg((('ffma@32(nsz)', 'ma', ('bcsel', ('feq', a, 0.0), 0.0, '#b(is_not_const_zero)'), c), ('ffmaz', 'ma', b, c), has_fmulz), {'ma' : a}), # b == 0.0 ? 1.0 : fexp2(fmul(a, b)) -> fexp2(fmulz(a, b)) - *add_fabs_fneg((('bcsel(nsz,nnan,ninf)', ('feq(ignore_exact)', b, 0.0), 1.0, ('fexp2', ('fmul@32', a, 'mb'))), + *add_fabs_fneg((('bcsel(nsz,nnan,ninf)', ('feq', b, 0.0), 1.0, ('fexp2', ('fmul@32', a, 'mb'))), ('fexp2', ('fmulz', a, 'mb')), has_fmulz), {'mb': b}), - *add_fabs_fneg((('bcsel', ('feq(ignore_exact)', b, 0.0), 1.0, ('fexp2', ('fmulz', a, 'mb'))), + *add_fabs_fneg((('bcsel', ('feq', b, 0.0), 1.0, ('fexp2', ('fmulz', a, 'mb'))), ('fexp2', ('fmulz', a, 'mb'))), {'mb': b}), ] @@ -787,10 +787,10 @@ optimizations.extend([ (('bcsel(is_only_used_as_float)', ('feq', a, 'b(is_not_zero)'), b, a), a), (('bcsel(is_only_used_as_float)', ('fneu', a, 'b(is_not_zero)'), a, b), a), - (('bcsel', ('feq(ignore_exact)', a, 0), 0, ('fsat', ('fmul', a, 'b(is_a_number)'))), ('fsat(preserve_sz)', ('fmul', a, b))), - (('bcsel', ('fneu(ignore_exact)', a, 0), ('fsat', ('fmul', a, 'b(is_a_number)')), 0), ('fsat(preserve_sz)', ('fmul', a, b))), - (('bcsel', ('feq(ignore_exact)', a, 0), b, ('fadd', a, 'b(is_not_zero)')), ('fadd', a, b)), - (('bcsel', ('fneu(ignore_exact)', a, 0), ('fadd', a, 'b(is_not_zero)'), b), ('fadd', a, b)), + (('bcsel', ('feq', a, 0), 0, ('fsat', ('fmul', a, 'b(is_a_number)'))), ('fsat(preserve_sz)', ('fmul', a, b))), + (('bcsel', ('fneu', a, 0), ('fsat', ('fmul', a, 'b(is_a_number)')), 0), ('fsat(preserve_sz)', ('fmul', a, b))), + (('bcsel', ('feq', a, 0), b, ('fadd', a, 'b(is_not_zero)')), ('fadd', a, b)), + (('bcsel', ('fneu', a, 0), ('fadd', a, 'b(is_not_zero)'), b), ('fadd', a, b)), # 0.0 >= b2f(a) # b2f(a) <= 0.0 diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c index f18e0f1fda8..0013c41aaad 100644 --- a/src/compiler/nir/nir_search.c +++ b/src/compiler/nir/nir_search.c @@ -374,12 +374,10 @@ match_expression(const nir_algebraic_table *table, const nir_search_expression * instr->def.bit_size != expr->value.bit_size) return false; - unsigned fp_math_ctrl = instr->fp_math_ctrl & ~(expr->ignore_exact ? nir_fp_exact : 0); - - if (expr->fp_math_ctrl_exclude & fp_math_ctrl) + if (expr->fp_math_ctrl_exclude & instr->fp_math_ctrl) return false; - state->fp_math_ctrl |= fp_math_ctrl; + state->fp_math_ctrl |= instr->fp_math_ctrl; assert(nir_op_infos[instr->op].num_inputs > 0); diff --git a/src/compiler/nir/nir_search.h b/src/compiler/nir/nir_search.h index 151599a02a6..ebf2169f1c5 100644 --- a/src/compiler/nir/nir_search.h +++ b/src/compiler/nir/nir_search.h @@ -136,9 +136,6 @@ typedef struct { /** In a replacement, add these fp_math_ctrl flags to the instruction. */ unsigned fp_math_ctrl_add : NIR_FP_MATH_CONTROL_BIT_COUNT; - /** Don't make the replacement exact if the search expression is exact. */ - bool ignore_exact : 1; - /** Whether the second source is a nir_search_value_constant */ bool src1_is_const : 1; diff --git a/src/gallium/drivers/r300/compiler/r300_nir_algebraic.py b/src/gallium/drivers/r300/compiler/r300_nir_algebraic.py index 7821188db64..7b18911f6d3 100644 --- a/src/gallium/drivers/r300/compiler/r300_nir_algebraic.py +++ b/src/gallium/drivers/r300/compiler/r300_nir_algebraic.py @@ -129,16 +129,16 @@ def main(): import nir_algebraic # pylint: disable=import-error r300_nir_lower_bool_to_float = [ - (('bcsel@32(is_only_used_as_float)', ('feq(ignore_exact)', 'a@32', 'b@32'), c, d), + (('bcsel@32(is_only_used_as_float)', ('feq', 'a@32', 'b@32'), c, d), ('fadd', ('fmul', c, ('seq', a, b)), ('fsub', d, ('fmul', d, ('seq', a, b)))), "!options->has_fused_comp_and_csel"), - (('bcsel@32(is_only_used_as_float)', ('fneu(ignore_exact)', 'a@32', 'b@32'), c, d), + (('bcsel@32(is_only_used_as_float)', ('fneu', 'a@32', 'b@32'), c, d), ('fadd', ('fmul', c, ('sne', a, b)), ('fsub', d, ('fmul', d, ('sne', a, b)))), "!options->has_fused_comp_and_csel"), - (('bcsel@32(is_only_used_as_float)', ('flt(ignore_exact)', 'a@32', 'b@32'), c, d), + (('bcsel@32(is_only_used_as_float)', ('flt', 'a@32', 'b@32'), c, d), ('fadd', ('fmul', c, ('slt', a, b)), ('fsub', d, ('fmul', d, ('slt', a, b)))), "!options->has_fused_comp_and_csel"), - (('bcsel@32(is_only_used_as_float)', ('fge(ignore_exact)', 'a@32', 'b@32'), c, d), + (('bcsel@32(is_only_used_as_float)', ('fge', 'a@32', 'b@32'), c, d), ('fadd', ('fmul', c, ('sge', a, b)), ('fsub', d, ('fmul', d, ('sge', a, b)))), "!options->has_fused_comp_and_csel"), (('bcsel@32(is_only_used_as_float)', ('feq', 'a@32', 'b@32'), c, d), @@ -152,13 +152,13 @@ def main(): ] r300_nir_lower_bool_to_float_fs = [ - (('bcsel@32(r300_is_only_used_as_float)', ('feq(ignore_exact)', 'a@32', 'b@32'), c, d), + (('bcsel@32(r300_is_only_used_as_float)', ('feq', 'a@32', 'b@32'), c, d), ('fcsel_ge', ('fneg', ('fabs', ('fadd', a, ('fneg', b)))), c, d)), - (('bcsel@32(r300_is_only_used_as_float)', ('fneu(ignore_exact)', 'a@32', 'b@32'), c, d), + (('bcsel@32(r300_is_only_used_as_float)', ('fneu', 'a@32', 'b@32'), c, d), ('fcsel_ge', ('fneg', ('fabs', ('fadd', a, ('fneg', b)))), d, c)), - (('bcsel@32(r300_is_only_used_as_float)', ('flt(ignore_exact)', 'a@32', 'b@32'), c, d), + (('bcsel@32(r300_is_only_used_as_float)', ('flt', 'a@32', 'b@32'), c, d), ('fcsel_ge', ('fadd', a, ('fneg', b)), d, c)), - (('bcsel@32(r300_is_only_used_as_float)', ('fge(ignore_exact)', 'a@32', 'b@32'), c, d), + (('bcsel@32(r300_is_only_used_as_float)', ('fge', 'a@32', 'b@32'), c, d), ('fcsel_ge', ('fadd', a, ('fneg', b)), c, d)), (('b2f32', ('feq', 'a@32', 'b@32')), ('fcsel_ge', ('fneg', ('fabs', ('fadd', a, ('fneg', b)))), 1.0, 0.0)),