From bd274e27bebff71329ba72ed6ccc5ccc0662a7ba Mon Sep 17 00:00:00 2001 From: Simon Perretta Date: Tue, 18 Feb 2025 12:08:55 +0000 Subject: [PATCH] pco: support dce for vregs Signed-off-by: Simon Perretta Acked-by: Erik Faye-Lund Part-of: --- src/imagination/.clang-format | 2 ++ src/imagination/pco/pco_internal.h | 10 ++++++++ src/imagination/pco/pco_opt.c | 39 +++++++++++++++++++++--------- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/imagination/.clang-format b/src/imagination/.clang-format index 66e8f9fdddd..2f6677a8896 100644 --- a/src/imagination/.clang-format +++ b/src/imagination/.clang-format @@ -304,6 +304,8 @@ ForEachMacros: [ 'pco_foreach_phase_in_igrp_rev', 'pco_foreach_phase_rev', 'pco_foreach_phi_src_in_instr', + 'pco_foreach_vreg_if_in_func', + 'pco_foreach_vreg_ssa_if_in_func', 'pvr_foreach_supported_tex_format', 'pvr_foreach_supported_tex_format_', 'pvr_foreach_supported_tex_format_compressed', diff --git a/src/imagination/pco/pco_internal.h b/src/imagination/pco/pco_internal.h index da51f533141..478a76e4308 100644 --- a/src/imagination/pco/pco_internal.h +++ b/src/imagination/pco/pco_internal.h @@ -550,6 +550,16 @@ PCO_DEFINE_CAST(pco_cf_node_as_func, pif = pco_next_if(pif)) \ if (pco_ref_is_ssa(pif->cond) && pco_ref_get_bits(pif->cond) == 1) +#define pco_foreach_vreg_if_in_func(pif, func) \ + for (pco_if *pif = pco_func_first_if(func); pif != NULL; \ + pif = pco_next_if(pif)) \ + if (pco_ref_is_vreg(pif->cond)) + +#define pco_foreach_vreg_ssa_if_in_func(pif, func) \ + for (pco_if *pif = pco_func_first_if(func); pif != NULL; \ + pif = pco_next_if(pif)) \ + if (pco_ref_is_vreg(pif->cond) || pco_ref_is_ssa(pif->cond)) + #define pco_foreach_if_in_func_from(pif, from) \ for (pco_if *pif = pco_next_if(from); pif != NULL; pif = pco_next_if(pif)) diff --git a/src/imagination/pco/pco_opt.c b/src/imagination/pco/pco_opt.c index 3fd7ffd2dab..ff15998102e 100644 --- a/src/imagination/pco/pco_opt.c +++ b/src/imagination/pco/pco_opt.c @@ -573,41 +573,56 @@ bool pco_dce(pco_shader *shader) { bool progress = false; BITSET_WORD *ssa_used; + BITSET_WORD *vreg_used; pco_foreach_func_in_shader (func, shader) { ssa_used = rzalloc_array_size(NULL, sizeof(*ssa_used), BITSET_WORDS(func->next_ssa)); - /* Collect used SSA sources. */ + vreg_used = rzalloc_array_size(NULL, + sizeof(*vreg_used), + BITSET_WORDS(func->next_vreg)); + + /* Collect used SSA/vreg sources. */ pco_foreach_instr_in_func (instr, func) { - pco_foreach_instr_src_ssa (psrc, instr) { - BITSET_SET(ssa_used, psrc->val); + pco_foreach_instr_src_vreg_ssa (psrc, instr) { + if (pco_ref_is_ssa(*psrc)) + BITSET_SET(ssa_used, psrc->val); + else + BITSET_SET(vreg_used, psrc->val); } } - pco_foreach_ssa_if_in_func (pif, func) { - BITSET_SET(ssa_used, pif->cond.val); + pco_foreach_vreg_ssa_if_in_func (pif, func) { + if (pco_ref_is_ssa(pif->cond)) + BITSET_SET(ssa_used, pif->cond.val); + else + BITSET_SET(vreg_used, pif->cond.val); } - /* Remove instructions with unused SSA destinations (if they also have no - * side-effects). + /* Remove instructions with unused SSA/vreg destinations (if they also + * have no side-effects). */ pco_foreach_instr_in_func_safe (instr, func) { - bool has_ssa_dests = false; + bool has_dce_dests = false; bool dests_used = false; - pco_foreach_instr_dest_ssa (pdest, instr) { - has_ssa_dests = true; - dests_used |= BITSET_TEST(ssa_used, pdest->val); + pco_foreach_instr_dest_vreg_ssa (pdest, instr) { + has_dce_dests = true; + if (pco_ref_is_ssa(*pdest)) + dests_used |= BITSET_TEST(ssa_used, pdest->val); + else + dests_used |= BITSET_TEST(vreg_used, pdest->val); } - if (has_ssa_dests && !dests_used && !instr_has_side_effects(instr)) { + if (has_dce_dests && !dests_used && !instr_has_side_effects(instr)) { pco_instr_delete(instr); progress = true; } } + ralloc_free(vreg_used); ralloc_free(ssa_used); }