From dbcbf6172677d46258530c70d582899551af2a98 Mon Sep 17 00:00:00 2001 From: Job Noorman Date: Wed, 13 Mar 2024 11:11:01 +0100 Subject: [PATCH] ir3: calculate SSA uses at the start of predicates RA When calculating SSA uses after reloading a def for the first time, the uses of the original def would not be complete anymore (since some of its uses may be replaced by a reloaded def). This causes problems when calculating the furthest first use to determine a value to be spilled. For example, something like: ssaX = foo # No free regs so this one is ignored ... bar ssaX, ssaY So Let's say we arrive at bar and neither ssaX nor ssaY are live and we have one free register. First, ssaX will get reloaded. Then, since there are no free registers left, we need to spill one. If we calculate SSA uses now, the ones for ssaX will not include bar which might cause us to select ssaX for spilling which shouldn't happen because it's used by the current instruction. This patch fixes this by calculating SSA uses at the start of RA. I haven't been able to measure a significant performance improvement when trying to postpone calculating the SSA uses. Fixes: 21cd9b9557d ("ir3: implement RA for predicate registers") Signed-off-by: Job Noorman Part-of: --- src/freedreno/ir3/ir3_ra_predicates.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/freedreno/ir3/ir3_ra_predicates.c b/src/freedreno/ir3/ir3_ra_predicates.c index 70f59460683..6ca8d3633a8 100644 --- a/src/freedreno/ir3/ir3_ra_predicates.c +++ b/src/freedreno/ir3/ir3_ra_predicates.c @@ -48,12 +48,6 @@ struct ra_predicates_ctx { unsigned num_regs; struct ir3_liveness *liveness; struct block_liveness *blocks_liveness; - - /* True once we spilled a register. This allows us to postpone the - * calculation of SSA uses and instruction counting until the first time we - * need to spill. This is useful since spilling is rare in general. - */ - bool spilled; }; static bool @@ -177,12 +171,6 @@ static void spill(struct ra_predicates_ctx *ctx, struct block_liveness *live, struct ir3_instruction *spill_location) { - if (!ctx->spilled) { - ir3_count_instructions_ra(ctx->ir); - ir3_find_ssa_uses_for(ctx->ir, ctx, is_predicate_use); - ctx->spilled = true; - } - unsigned furthest_first_use = 0; unsigned spill_reg = ~0; @@ -456,6 +444,8 @@ ir3_ra_predicates(struct ir3_shader_variant *v) ra_reg_is_predicate); ctx->blocks_liveness = rzalloc_array(ctx, struct block_liveness, ctx->liveness->block_count); + ir3_count_instructions_ra(ctx->ir); + ir3_find_ssa_uses_for(ctx->ir, ctx, is_predicate_use); foreach_block (block, &v->ir->block_list) { init_block_liveness(ctx, block);