From df2eaba4119e827a59596709373ad2491c4fbab4 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Fri, 19 Aug 2022 15:04:19 +0200 Subject: [PATCH] radeonsi: use nir_opt_large_constants earlier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calling it before nir_convert_to_lcssa helps in some cases, because the NIR is simpler and nir_opt_large_constants can detect that a variable is constant. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7059 CC: mesa-stable Reviewed-by: Marek Olšák Part-of: --- src/gallium/drivers/radeonsi/si_shader_nir.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c index 46c7e135955..beeaa9adb21 100644 --- a/src/gallium/drivers/radeonsi/si_shader_nir.c +++ b/src/gallium/drivers/radeonsi/si_shader_nir.c @@ -351,6 +351,21 @@ char *si_finalize_nir(struct pipe_screen *screen, void *nirptr) if (sscreen->options.inline_uniforms) nir_find_inlinable_uniforms(nir); + /* Lower large variables that are always constant with load_constant intrinsics, which + * get turned into PC-relative loads from a data section next to the shader. + * + * Run this once before lcssa because the added phis may prevent this + * pass from operating correctly. + * + * nir_opt_large_constants may use op_amul (see nir_build_deref_offset), + * or may create unneeded code, so run si_nir_opts if needed. + */ + NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_function_temp, NULL); + bool progress = false; + NIR_PASS(progress, nir, nir_opt_large_constants, glsl_get_natural_size_align_bytes, 16); + if (progress) + si_nir_opts(sscreen, nir, false); + NIR_PASS_V(nir, nir_convert_to_lcssa, true, true); /* required by divergence analysis */ NIR_PASS_V(nir, nir_divergence_analysis); /* to find divergent loops */