From c6be264c2da75c655fb2536245e2ec5075868172 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Wed, 6 May 2026 22:59:20 -0400 Subject: [PATCH] i915/corm: add copy propagation before algebraic late MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nir_lower_io introduces identity vec instructions that block nir_opt_algebraic_late's fadd+fmul→ffma fusion pattern. Adding nir_opt_copy_prop + nir_opt_dce before algebraic cleans these up, enabling ffma fusion and eliminating redundant vec construction. shader-db (I915_FS=nir): 48/403 compiled, 62 alu shader-db (I915_FS=both): nir won 48 (26 identical, 16 tied, 6 better), 236 TGSI, 119 neither Assisted-by: Claude --- src/gallium/drivers/i915/i915_state.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/gallium/drivers/i915/i915_state.c b/src/gallium/drivers/i915/i915_state.c index 12da6b72266..10a185db957 100644 --- a/src/gallium/drivers/i915/i915_state.c +++ b/src/gallium/drivers/i915/i915_state.c @@ -561,6 +561,20 @@ scalarize_vector_bools(const nir_instr *instr, const void *data) alu->op == nir_op_fcsel_gt; } +static bool +lower_fsqrt_filter(const nir_instr *instr, UNUSED const void *data) +{ + return instr->type == nir_instr_type_alu && + nir_instr_as_alu(instr)->op == nir_op_fsqrt; +} + +static nir_def * +lower_fsqrt_impl(nir_builder *b, nir_instr *instr, UNUSED void *data) +{ + nir_def *src = nir_instr_as_alu(instr)->src[0].src.ssa; + return nir_fmul(b, src, nir_frsq(b, src)); +} + static char * i915_check_control_flow(nir_shader *s) { @@ -739,6 +753,11 @@ i915_create_fs_state(struct pipe_context *pipe, NIR_PASS(_, nir_s, nir_lower_alu_to_scalar, scalarize_vector_bools, NULL); NIR_PASS(_, nir_s, nir_opt_vectorize, NULL, NULL); NIR_PASS(_, nir_s, nir_lower_bool_to_float, false); + NIR_PASS(_, nir_s, nir_shader_lower_instructions, lower_fsqrt_filter, + lower_fsqrt_impl, NULL); + NIR_PASS(_, nir_s, nir_opt_copy_prop); + NIR_PASS(_, nir_s, nir_opt_cse); + NIR_PASS(_, nir_s, nir_opt_dce); NIR_PASS(_, nir_s, nir_opt_algebraic); NIR_PASS(_, nir_s, nir_opt_algebraic_late); NIR_PASS(_, nir_s, nir_opt_dce);