From 5adab502838e25be85fe2181a16fa035b1270309 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Wed, 2 Jul 2025 19:37:25 -0700 Subject: [PATCH] brw/nir: Use nir_opt_reassociate_matrix_mul This needs to be called before intel_nir_opt_peephole_ffma, so I arbitrarilly decided to call it right before. All Intel platforms had similar results. (Lunar Lake shown) total instructions in shared programs: 17120227 -> 17118227 (-0.01%) instructions in affected programs: 5854 -> 3854 (-34.16%) helped: 51 / HURT: 0 total cycles in shared programs: 895497762 -> 894733940 (-0.09%) cycles in affected programs: 4603518 -> 3839696 (-16.59%) helped: 95 / HURT: 21 LOST: 1 GAINED: 0 Reviewed-by: Matt Turner Part-of: --- src/intel/compiler/brw_nir.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c index 291e6922fb7..1f9fdb52a47 100644 --- a/src/intel/compiler/brw_nir.c +++ b/src/intel/compiler/brw_nir.c @@ -2068,6 +2068,12 @@ brw_postprocess_nir(nir_shader *nir, const struct brw_compiler *compiler, if (OPT(nir_lower_int64)) brw_nir_optimize(nir, devinfo); + /* This pass specifically looks for sequences of fmul and fadd that + * intel_nir_opt_peephole_ffma will try to eliminate. Call this + * reassociation pass first. + */ + OPT(nir_opt_reassociate_matrix_mul); + /* Try and fuse multiply-adds, if successful, run shrink_vectors to * avoid peephole_ffma to generate things like this : * vec16 ssa_0 = ...