From 5ed567fea16d0f15c1b112b65064db0c39c60fcc Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Mon, 13 Feb 2023 17:37:15 +0100 Subject: [PATCH] ir3: Run divergence analysis at the end Part-of: --- src/freedreno/ir3/ir3_compiler.c | 2 ++ src/freedreno/ir3/ir3_compiler_nir.c | 10 ++++++++++ src/freedreno/ir3/ir3_context.c | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/src/freedreno/ir3/ir3_compiler.c b/src/freedreno/ir3/ir3_compiler.c index 0cf419e090d..1ad6a5f5ca0 100644 --- a/src/freedreno/ir3/ir3_compiler.c +++ b/src/freedreno/ir3/ir3_compiler.c @@ -124,6 +124,8 @@ static const nir_shader_compiler_options ir3_base_options = { .lower_int64_options = (nir_lower_int64_options)~0, .lower_doubles_options = (nir_lower_doubles_options)~0, + + .divergence_analysis_options = nir_divergence_uniform_load_tears, }; struct ir3_compiler * diff --git a/src/freedreno/ir3/ir3_compiler_nir.c b/src/freedreno/ir3/ir3_compiler_nir.c index a0d94fca16d..5684bcc77e3 100644 --- a/src/freedreno/ir3/ir3_compiler_nir.c +++ b/src/freedreno/ir3/ir3_compiler_nir.c @@ -3569,6 +3569,16 @@ emit_phi(struct ir3_context *ctx, nir_phi_instr *nphi) dst = ir3_get_def(ctx, &nphi->def, 1); + if (exec_list_is_singular(&nphi->srcs)) { + nir_phi_src *src = list_entry(exec_list_get_head(&nphi->srcs), + nir_phi_src, node); + if (nphi->def.divergent == src->src.ssa->divergent) { + dst[0] = ir3_get_src(ctx, &src->src)[0]; + ir3_put_def(ctx, &nphi->def); + return; + } + } + phi = ir3_instr_create(ctx->block, OPC_META_PHI, 1, exec_list_length(&nphi->srcs)); __ssa_dst(phi); diff --git a/src/freedreno/ir3/ir3_context.c b/src/freedreno/ir3/ir3_context.c index 885e50d1dac..776082076b2 100644 --- a/src/freedreno/ir3/ir3_context.c +++ b/src/freedreno/ir3/ir3_context.c @@ -120,8 +120,15 @@ ir3_context_init(struct ir3_compiler *compiler, struct ir3_shader *shader, if ((so->type == MESA_SHADER_FRAGMENT) && compiler->has_fs_tex_prefetch) NIR_PASS_V(ctx->s, ir3_nir_lower_tex_prefetch); + NIR_PASS(progress, ctx->s, nir_convert_to_lcssa, true, true); + NIR_PASS(progress, ctx->s, nir_lower_phis_to_scalar, true); + /* This has to go at the absolute end to make sure that all SSA defs are + * correctly marked. + */ + NIR_PASS_V(ctx->s, nir_divergence_analysis); + /* Super crude heuristic to limit # of tex prefetch in small * shaders. This completely ignores loops.. but that's really * not the worst of it's problems. (A frag shader that has