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 <mhenning@darkrefraction.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41042>
This commit is contained in:
Karol Herbst 2026-04-19 01:01:22 +02:00 committed by Marge Bot
parent 620835926d
commit 4cd64165a3

View file

@ -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.