From 4cd64165a383d54b1e292a7f2c147098c8cb3f77 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Sun, 19 Apr 2026 01:01:22 +0200 Subject: [PATCH] nak/lower_cf: remove single src phis When lowering cf we go out of SSA which translates phis into reg intrinsics. However when converting them back to SSA, initially single source phis now have an undef source leading to increased register pressure on the NAK side. This also hinders copy propagation as it's not designed to handle sources through phis yet. Totals from 50621 (4.17% of 1212873) affected shaders: CodeSize: 1605273744 -> 1621029728 (+0.98%); split: -0.34%, +1.32% Number of GPRs: 4673586 -> 4067935 (-12.96%); split: -12.97%, +0.01% SLM Size: 263428 -> 258176 (-1.99%) Static cycle count: 2599838439 -> 2586392435 (-0.52%); split: -1.11%, +0.59% Spills to memory: 23512 -> 15527 (-33.96%) Fills from memory: 23512 -> 15527 (-33.96%) Spills to reg: 64590 -> 57328 (-11.24%); split: -13.83%, +2.58% Fills from reg: 55559 -> 44319 (-20.23%); split: -22.66%, +2.42% Max warps/SM: 1189396 -> 1347600 (+13.30%) Reviewed-by: Mel Henning Part-of: --- src/nouveau/compiler/nak_nir_lower_cf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/nouveau/compiler/nak_nir_lower_cf.c b/src/nouveau/compiler/nak_nir_lower_cf.c index 01276c4a4db..817f6de4d73 100644 --- a/src/nouveau/compiler/nak_nir_lower_cf.c +++ b/src/nouveau/compiler/nak_nir_lower_cf.c @@ -442,6 +442,14 @@ lower_cf_func(nir_function *func) /* We use this in block_is_merge() */ nir_metadata_require(old_impl, nir_metadata_dominance | nir_metadata_divergence); + /* We get rid of single source phis, because they would be converted to phis + * with undef after lowering regs to SSA. + */ + nir_foreach_block(block, old_impl) { + if (nir_block_num_preds(block) <= 1) + nir_remove_single_src_phis_block(block); + } + /* First, we temporarily get rid of SSA. This will make all our block * motion way easier. Ask the pass to place reg writes directly in the * immediate predecessors of the phis instead of trying to be clever.