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: 21cd9b9557 ("ir3: implement RA for predicate registers")
Signed-off-by: Job Noorman <jnoorman@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28148>
This commit is contained in:
Job Noorman 2024-03-13 11:11:01 +01:00 committed by Marge Bot
parent 22f64a1fe3
commit dbcbf61726
1 changed files with 2 additions and 12 deletions

View File

@ -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);