From f00143acc3afe4e4009cef007a643ff10ab0eada Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 4 May 2023 00:55:42 -0700 Subject: [PATCH] intel/compiler: Fold constants after distributing source modifiers This can generate things like fneg! of load_const, which is silly. Fold those away into an actual constant. Only do so on the scalar backend because there's a comment above that the vec4 backend doesn't want any new constants this late, and I'm inclined to believe it. fossil-db stats show a very minor improvement: Totals: Instrs: 203091223 -> 203091099 (-0.00%); split: -0.00%, +0.00% Cycles: 14410638075 -> 14410577067 (-0.00%); split: -0.00%, +0.00% Totals from 20 (0.00% of 665070) affected shaders: Instrs: 27067 -> 26943 (-0.46%); split: -0.47%, +0.01% Cycles: 2687958 -> 2626950 (-2.27%); split: -2.27%, +0.00% Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/compiler/brw_nir.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c index 9f5d2c6..5d48dd4 100644 --- a/src/intel/compiler/brw_nir.c +++ b/src/intel/compiler/brw_nir.c @@ -1639,6 +1639,9 @@ brw_postprocess_nir(nir_shader *nir, const struct brw_compiler *compiler, OPT(nir_lower_alu_to_scalar, NULL, NULL); while (OPT(nir_opt_algebraic_distribute_src_mods)) { + if (is_scalar) + OPT(nir_opt_constant_folding); + OPT(nir_copy_prop); OPT(nir_opt_dce); OPT(nir_opt_cse); -- 2.7.4