From 70c22d38945223fbdef699c8af60f8be95b178c8 Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Fri, 23 Jul 2021 11:56:14 +0200 Subject: [PATCH] ir3/ra: Fix available bitset for live-through collect srcs When we mark live-through sources that are merged with the destination as killed, we kept the bitsets in sync, but we forgot to keep them in sync when unmarking them after allocating the destination. The result was that "available" wasn't correct for any instruction afterwards. This resulted in a bad register allocation with IR3_SHADER_DEBUG=spillall for a dEQP-VK test. While we're changing this, use ra_foreach_src(). Fixes: 0ffcb19b9d9 ("ir3: Rewrite register allocation") Part-of: --- src/freedreno/ir3/ir3_ra.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/freedreno/ir3/ir3_ra.c b/src/freedreno/ir3/ir3_ra.c index a30455ea277..46fd8d3afdb 100644 --- a/src/freedreno/ir3/ir3_ra.c +++ b/src/freedreno/ir3/ir3_ra.c @@ -551,6 +551,18 @@ ra_file_mark_killed(struct ra_file *file, struct ra_interval *interval) interval->is_killed = true; } +static void +ra_file_unmark_killed(struct ra_file *file, struct ra_interval *interval) +{ + assert(!interval->interval.parent); + + for (physreg_t i = interval->physreg_start; i < interval->physreg_end; i++) { + BITSET_CLEAR(file->available, i); + } + + interval->is_killed = false; +} + static physreg_t ra_interval_get_physreg(const struct ra_interval *interval) { @@ -1314,15 +1326,11 @@ handle_collect(struct ra_ctx *ctx, struct ir3_instruction *instr) */ physreg_t dst_fixed = (physreg_t)~0u; - for (unsigned i = 0; i < instr->srcs_count; i++) { - if (!ra_reg_is_src(instr->srcs[i])) - continue; - - if (instr->srcs[i]->flags & IR3_REG_FIRST_KILL) { - mark_src_killed(ctx, instr->srcs[i]); + ra_foreach_src (src, instr) { + if (src->flags & IR3_REG_FIRST_KILL) { + mark_src_killed(ctx, src); } - struct ir3_register *src = instr->srcs[i]; struct ra_interval *interval = &ctx->intervals[src->def->name]; if (src->def->merge_set != dst_set || interval->is_killed) @@ -1350,11 +1358,7 @@ handle_collect(struct ra_ctx *ctx, struct ir3_instruction *instr) allocate_dst(ctx, instr->dsts[0]); /* Remove the temporary is_killed we added */ - for (unsigned i = 0; i < instr->srcs_count; i++) { - if (!ra_reg_is_src(instr->srcs[i])) - continue; - - struct ir3_register *src = instr->srcs[i]; + ra_foreach_src (src, instr) { struct ra_interval *interval = &ctx->intervals[src->def->name]; while (interval->interval.parent != NULL) { interval = ir3_reg_interval_to_ra_interval(interval->interval.parent); @@ -1362,8 +1366,9 @@ handle_collect(struct ra_ctx *ctx, struct ir3_instruction *instr) /* Filter out cases where it actually should be killed */ if (interval != &ctx->intervals[src->def->name] || - !(src->flags & IR3_REG_KILL)) - interval->is_killed = false; + !(src->flags & IR3_REG_KILL)) { + ra_file_unmark_killed(ra_get_file(ctx, src), interval); + } } ra_foreach_src_rev (src, instr) {