From 2913b81364dc1498e487f6644ec4f7f05d6bfa63 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Sun, 8 Mar 2026 14:48:35 +0100 Subject: [PATCH] nir/search_helpers: assume float sources without preserve flag can't be inf/nan For example, this should let us avoid needing one pattern with is_a_number and one with nnan. Foz-DB Navi48: Totals from 3564 (3.11% of 114655) affected shaders: Instrs: 8256755 -> 8255042 (-0.02%); split: -0.02%, +0.00% CodeSize: 43143184 -> 43123192 (-0.05%); split: -0.05%, +0.00% VGPRs: 268252 -> 268240 (-0.00%) Latency: 218890225 -> 218881157 (-0.00%); split: -0.00%, +0.00% InvThroughput: 31044516 -> 31042297 (-0.01%); split: -0.01%, +0.00% VClause: 96074 -> 96067 (-0.01%); split: -0.01%, +0.00% SClause: 218042 -> 218037 (-0.00%); split: -0.00%, +0.00% Copies: 508677 -> 508661 (-0.00%); split: -0.01%, +0.01% Branches: 148570 -> 148569 (-0.00%) PreSGPRs: 228110 -> 228082 (-0.01%); split: -0.01%, +0.00% PreVGPRs: 231996 -> 231982 (-0.01%) VALU: 4516327 -> 4515321 (-0.02%); split: -0.02%, +0.00% SALU: 1353696 -> 1353590 (-0.01%); split: -0.01%, +0.00% VMEM: 182189 -> 182179 (-0.01%) SMEM: 344771 -> 344756 (-0.00%) VOPD: 29463 -> 29438 (-0.08%) Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_search_helpers.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h index c6e20d78892..454e62b934e 100644 --- a/src/compiler/nir/nir_search_helpers.h +++ b/src/compiler/nir/nir_search_helpers.h @@ -853,14 +853,28 @@ xz_components_unused(const nir_alu_instr *instr) return (nir_def_components_read(&instr->def) & 0x5) == 0; } -#define RELATION(r, exclude) \ +#define RELATION(r, _exclude) \ static inline bool \ is_##r(const nir_search_state *state, const nir_alu_instr *instr, \ unsigned src, UNUSED unsigned num_components, \ UNUSED const uint8_t *swizzle) \ { \ + fp_class_mask exclude = _exclude; \ + if (exclude & (FP_CLASS_ANY_INF | FP_CLASS_NAN)) { \ + /* fp_math_ctrl lets us assume inputs are not NaN/Inf for float sources. */ \ + const nir_op_info *op_info = &nir_op_infos[(int)instr->op]; \ + nir_alu_type base_type = nir_alu_type_get_base_type(op_info->input_types[src]); \ + if (base_type == nir_type_float) { \ + if (!nir_alu_instr_is_inf_preserve(instr)) \ + exclude &= ~FP_CLASS_ANY_INF; \ + if (!nir_alu_instr_is_nan_preserve(instr)) \ + exclude &= ~FP_CLASS_NAN; \ + if (!exclude) \ + return true; \ + } \ + } \ const fp_class_mask fp_class = nir_analyze_fp_class(state->range_ht, instr->src[src].src.ssa); \ - return (fp_class & (exclude)) == 0; \ + return (fp_class & exclude) == 0; \ } #define RELATION_AND_NUM(r, exclude) \