aco: summarize register demand after handling branches
authorRhys Perry <pendingchaos02@gmail.com>
Tue, 8 Aug 2023 20:02:21 +0000 (21:02 +0100)
committerMarge Bot <emma+marge@anholt.net>
Mon, 14 Aug 2023 15:08:37 +0000 (15:08 +0000)
Fixes various dEQP-VK.ray_query.builtin.rayqueryterminate.* crashes.

fossil-db (gfx1100):
Totals from 196 (0.15% of 133461) affected shaders:
PreSGPRs: 8342 -> 8558 (+2.59%)

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Fixes: 5a536eca9ca7 ("aco: calculate correct register demand for branch instructions")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24579>

src/amd/compiler/aco_live_var_analysis.cpp

index aa837b3..989e26b 100644 (file)
@@ -132,7 +132,6 @@ process_live_temps_per_block(Program* program, live& lives, Block* block, unsign
    RegisterDemand new_demand;
 
    register_demand.resize(block->instructions.size());
-   RegisterDemand block_register_demand;
    IDSet live = lives.live_out[block->index];
 
    /* initialize register demand */
@@ -209,15 +208,8 @@ process_live_temps_per_block(Program* program, live& lives, Block* block, unsign
          RegisterDemand before_instr = new_demand;
          handle_def_fixed_to_op(&register_demand[idx], before_instr, insn, op_idx);
       }
-
-      block_register_demand.update(register_demand[idx]);
    }
 
-   /* update block's register demand for a last time */
-   block_register_demand.update(new_demand);
-   if (program->progress < CompilationProgress::after_ra)
-      block->register_demand = block_register_demand;
-
    /* handle phi definitions */
    uint16_t linear_phi_defs = 0;
    int phi_idx = idx;
@@ -497,13 +489,21 @@ live_var_analysis(Program* program)
       unsigned block_idx = --worklist;
       process_live_temps_per_block(program, result, &program->blocks[block_idx], worklist,
                                    phi_info);
-      new_demand.update(program->blocks[block_idx].register_demand);
    }
 
    /* Handle branches: we will insert copies created for linear phis just before the branch. */
    for (Block& block : program->blocks) {
       result.register_demand[block.index].back().sgpr += phi_info[block.index].linear_phi_defs;
       result.register_demand[block.index].back().sgpr -= phi_info[block.index].linear_phi_ops;
+
+      /* update block's register demand */
+      if (program->progress < CompilationProgress::after_ra) {
+         block.register_demand = RegisterDemand();
+         for (RegisterDemand& demand : result.register_demand[block.index])
+            block.register_demand.update(demand);
+      }
+
+      new_demand.update(block.register_demand);
    }
 
    /* calculate the program's register demand and number of waves */