From 14de650d58cf41647f7da56dac129907a00f65e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Thu, 22 Aug 2024 11:58:42 +0200 Subject: [PATCH] aco: call nir_copy_prop() and nir_opt_dce() before instruction selection Totals from 1037 (1.31% of 79395) affected shaders: (Navi21) MaxWaves: 18760 -> 18960 (+1.07%) Instrs: 4865258 -> 4860063 (-0.11%); split: -0.11%, +0.00% CodeSize: 27094112 -> 27089224 (-0.02%); split: -0.06%, +0.04% VGPRs: 68816 -> 68000 (-1.19%) SpillVGPRs: 2140 -> 2105 (-1.64%) Scratch: 4237312 -> 4234240 (-0.07%) Latency: 55894512 -> 55748035 (-0.26%); split: -0.31%, +0.05% InvThroughput: 11611286 -> 11372897 (-2.05%); split: -2.09%, +0.03% VClause: 145331 -> 145285 (-0.03%); split: -0.04%, +0.01% SClause: 150339 -> 150338 (-0.00%) Copies: 472476 -> 468470 (-0.85%); split: -0.88%, +0.03% Branches: 206562 -> 206067 (-0.24%); split: -0.24%, +0.00% PreVGPRs: 61747 -> 61361 (-0.63%) VALU: 3116434 -> 3112660 (-0.12%); split: -0.13%, +0.00% SALU: 723154 -> 722887 (-0.04%); split: -0.04%, +0.01% VMEM: 238656 -> 238586 (-0.03%) Part-of: --- src/amd/compiler/aco_instruction_selection_setup.cpp | 5 ++++- src/amd/compiler/tests/test_isel.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/amd/compiler/aco_instruction_selection_setup.cpp b/src/amd/compiler/aco_instruction_selection_setup.cpp index 05d89276e8e..45d5c8f85d4 100644 --- a/src/amd/compiler/aco_instruction_selection_setup.cpp +++ b/src/amd/compiler/aco_instruction_selection_setup.cpp @@ -252,7 +252,10 @@ void setup_nir(isel_context* ctx, nir_shader* nir) { nir_convert_to_lcssa(nir, true, false); - nir_lower_phis_to_scalar(nir, true); + if (nir_lower_phis_to_scalar(nir, true)) { + nir_copy_prop(nir); + nir_opt_dce(nir); + } nir_function_impl* func = nir_shader_get_entrypoint(nir); nir_index_ssa_defs(func); diff --git a/src/amd/compiler/tests/test_isel.cpp b/src/amd/compiler/tests/test_isel.cpp index 2c45871e18d..3345a7f3d1a 100644 --- a/src/amd/compiler/tests/test_isel.cpp +++ b/src/amd/compiler/tests/test_isel.cpp @@ -299,6 +299,8 @@ BEGIN_TEST(isel.cf.unreachable_continue.uniform_break) nb->cursor = nir_after_phis(nir_loop_first_block(loop)); nir_builder_instr_insert(nb, &phi[0]->instr); nir_builder_instr_insert(nb, &phi[1]->instr); + nir_unit_test_amd(nb, &phi[0]->def); + nir_unit_test_amd(nb, &phi[1]->def); finish_isel_test(); END_TEST @@ -368,6 +370,8 @@ BEGIN_TEST(isel.cf.unreachable_continue.divergent_break) nb->cursor = nir_after_phis(nir_loop_first_block(loop)); nir_builder_instr_insert(nb, &phi[0]->instr); nir_builder_instr_insert(nb, &phi[1]->instr); + nir_unit_test_amd(nb, &phi[0]->def); + nir_unit_test_amd(nb, &phi[1]->def); finish_isel_test(); END_TEST @@ -536,6 +540,8 @@ BEGIN_TEST(isel.cf.unreachable_continue.mixed_break) nb->cursor = nir_after_phis(nir_loop_first_block(loop)); nir_builder_instr_insert(nb, &phi[0]->instr); nir_builder_instr_insert(nb, &phi[1]->instr); + nir_unit_test_amd(nb, &phi[0]->def); + nir_unit_test_amd(nb, &phi[1]->def); finish_isel_test(); END_TEST @@ -648,6 +654,8 @@ BEGIN_TEST(isel.cf.unreachable_continue.nested_mixed_break) nb->cursor = nir_after_phis(nir_loop_first_block(loop)); nir_builder_instr_insert(nb, &phi[0]->instr); nir_builder_instr_insert(nb, &phi[1]->instr); + nir_unit_test_amd(nb, &phi[0]->def); + nir_unit_test_amd(nb, &phi[1]->def); finish_isel_test(); END_TEST @@ -833,6 +841,7 @@ BEGIN_TEST(isel.cf.hidden_continue) nb->cursor = nir_after_phis(nir_loop_first_block(loop)); nir_builder_instr_insert(nb, &phi->instr); + nir_unit_test_amd(nb, &phi->def); finish_isel_test(); END_TEST @@ -876,6 +885,7 @@ BEGIN_TEST(isel.cf.hidden_break) nir_def_init(&phi->instr, &phi->def, 1, 32); nir_phi_instr_add_src(phi, block, brk); nir_builder_instr_insert(nb, &phi->instr); + nir_unit_test_amd(nb, &phi->def); finish_isel_test(); END_TEST