From aa4b1d314e6690ba4e0b26fb0bb33e243065f015 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Mon, 14 Nov 2022 15:16:48 +1100 Subject: [PATCH] glsl: copy prop vars before scalarizing alus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This generally gives us better results and doing it here in nir will also allow us to remove more glsl optimisation calls that do a similiar thing for us. (Updated shader-db results by idr.) Tiger Lake, Ice Lake, and Skylake had similar results. (Ice Lake shown) total instructions in shared programs: 20246333 -> 20240715 (-0.03%) instructions in affected programs: 235253 -> 229635 (-2.39%) helped: 425 / HURT: 114 total cycles in shared programs: 891730115 -> 891631113 (-0.01%) cycles in affected programs: 37347925 -> 37248923 (-0.27%) helped: 952 / HURT: 692 total spills in shared programs: 7072 -> 6716 (-5.03%) spills in affected programs: 505 -> 149 (-70.50%) helped: 7 / HURT: 0 total fills in shared programs: 9897 -> 8511 (-14.00%) fills in affected programs: 1674 -> 288 (-82.80%) helped: 7 / HURT: 0 total sends in shared programs: 1053685 -> 1053411 (-0.03%) sends in affected programs: 2821 -> 2547 (-9.71%) helped: 30 HURT: 2 LOST: 13 GAINED: 13 Broadwell and Haswell had similar results. (Broadwell shown) total instructions in shared programs: 18149157 -> 18147271 (-0.01%) instructions in affected programs: 204630 -> 202744 (-0.92%) helped: 294 / HURT: 121 total cycles in shared programs: 939488196 -> 939508444 (<.01%) cycles in affected programs: 36394777 -> 36415025 (0.06%) helped: 718 / HURT: 620 total sends in shared programs: 1005426 -> 1005152 (-0.03%) sends in affected programs: 2821 -> 2547 (-9.71%) helped: 30 / HURT: 2 LOST: 2 GAINED: 2 Reviewed-by: Marek Olšák Reviewed-by: Ian Romanick Tested-by: Ian Romanick Part-of: --- src/mesa/state_tracker/st_glsl_to_nir.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index a994e65f81b..3a7b5e012b1 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -408,8 +408,12 @@ st_nir_preprocess(struct st_context *st, struct gl_program *prog, } if (options->lower_to_scalar) { - NIR_PASS_V(nir, nir_lower_alu_to_scalar, - options->lower_to_scalar_filter, NULL); + NIR_PASS_V(nir, nir_remove_dead_variables, + nir_var_function_temp | nir_var_shader_temp | + nir_var_mem_shared, NULL); + NIR_PASS_V(nir, nir_opt_copy_prop_vars); + NIR_PASS_V(nir, nir_lower_alu_to_scalar, + options->lower_to_scalar_filter, NULL); } /* before buffers and vars_to_ssa */