From d81d5b7d0043acfdeee7bfea2352ba993a8fbca3 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Thu, 11 Jul 2024 11:42:28 +0100 Subject: [PATCH] aco: use dominance helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the passes slightly faster. Signed-off-by: Rhys Perry Reviewed-by: Daniel Schürmann Part-of: --- src/amd/compiler/aco_lower_to_cssa.cpp | 14 ++++++-------- src/amd/compiler/aco_opt_value_numbering.cpp | 7 +++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/amd/compiler/aco_lower_to_cssa.cpp b/src/amd/compiler/aco_lower_to_cssa.cpp index a25eee2b841..4a9b71fa689 100644 --- a/src/amd/compiler/aco_lower_to_cssa.cpp +++ b/src/amd/compiler/aco_lower_to_cssa.cpp @@ -146,14 +146,12 @@ inline bool dominates(cssa_ctx& ctx, Temp a, Temp b) { assert(defined_after(ctx, b, a)); - merge_node& node_a = ctx.merge_node_table[a.id()]; - merge_node& node_b = ctx.merge_node_table[b.id()]; - unsigned idom = node_b.defined_at; - while (idom > node_a.defined_at) - idom = b.regClass().type() == RegType::vgpr ? ctx.program->blocks[idom].logical_idom - : ctx.program->blocks[idom].linear_idom; - - return idom == node_a.defined_at; + Block& parent = ctx.program->blocks[ctx.merge_node_table[a.id()].defined_at]; + Block& child = ctx.program->blocks[ctx.merge_node_table[b.id()].defined_at]; + if (b.regClass().type() == RegType::vgpr) + return dominates_logical(parent, child); + else + return dominates_linear(parent, child); } /* Checks whether some variable is live-out, not considering any phi-uses. */ diff --git a/src/amd/compiler/aco_opt_value_numbering.cpp b/src/amd/compiler/aco_opt_value_numbering.cpp index e040221be61..039d36527c8 100644 --- a/src/amd/compiler/aco_opt_value_numbering.cpp +++ b/src/amd/compiler/aco_opt_value_numbering.cpp @@ -263,6 +263,13 @@ struct vn_ctx { bool dominates(vn_ctx& ctx, uint32_t parent, uint32_t child) { + Block& parent_b = ctx.program->blocks[parent]; + Block& child_b = ctx.program->blocks[child]; + if (!dominates_logical(parent_b, child_b) || parent_b.loop_nest_depth > child_b.loop_nest_depth) + return false; + if (parent_b.loop_nest_depth == child_b.loop_nest_depth && parent_b.loop_nest_depth == 0) + return true; + unsigned parent_loop_nest_depth = ctx.program->blocks[parent].loop_nest_depth; while (parent < child && parent_loop_nest_depth <= ctx.program->blocks[child].loop_nest_depth) child = ctx.program->blocks[child].logical_idom;