diff --git a/src/amd/compiler/aco_live_var_analysis.cpp b/src/amd/compiler/aco_live_var_analysis.cpp index 9160cb55583..374e2f33f8f 100644 --- a/src/amd/compiler/aco_live_var_analysis.cpp +++ b/src/amd/compiler/aco_live_var_analysis.cpp @@ -49,28 +49,30 @@ handle_def_fixed_to_op(RegisterDemand* demand, RegisterDemand demand_before, Ins RegisterDemand get_temp_registers(aco_ptr& instr) { - RegisterDemand temp_registers; + RegisterDemand demand_before; + RegisterDemand demand_after; for (Definition def : instr->definitions) { - if (!def.isTemp()) - continue; if (def.isKill()) - temp_registers += def.getTemp(); + demand_after += def.getTemp(); + else if (def.isTemp()) + demand_before -= def.getTemp(); } for (Operand op : instr->operands) { - if (op.isTemp() && op.isLateKill() && op.isFirstKill()) - temp_registers += op.getTemp(); + if (op.isFirstKill()) { + demand_before += op.getTemp(); + if (op.isLateKill()) + demand_after += op.getTemp(); + } } int op_idx = get_op_fixed_to_def(instr.get()); - if (op_idx != -1 && !instr->operands[op_idx].isKill()) { - RegisterDemand before_instr; - before_instr -= get_live_changes(instr); - handle_def_fixed_to_op(&temp_registers, before_instr, instr.get(), op_idx); - } + if (op_idx != -1 && !instr->operands[op_idx].isKill()) + demand_before += instr->definitions[0].getTemp(); - return temp_registers; + demand_after.update(demand_before); + return demand_after; } RegisterDemand @@ -190,6 +192,8 @@ process_live_temps_per_block(Program* program, Block* block, unsigned& worklist, RegisterDemand before_instr = new_demand; handle_def_fixed_to_op(®ister_demand[idx], before_instr, insn, op_idx); } + + register_demand[idx].update(new_demand); } /* handle phi definitions */ diff --git a/src/amd/compiler/aco_spill.cpp b/src/amd/compiler/aco_spill.cpp index 65951058f8d..da9efc65677 100644 --- a/src/amd/compiler/aco_spill.cpp +++ b/src/amd/compiler/aco_spill.cpp @@ -993,11 +993,9 @@ process_block(spill_ctx& ctx, unsigned block_idx, Block* block, RegisterDemand s spilled_registers -= new_tmp; } - /* check if register demand is low enough before and after the current instruction */ + /* check if register demand is low enough during and after the current instruction */ if (block->register_demand.exceeds(ctx.target_pressure)) { - RegisterDemand new_demand = ctx.program->live.register_demand[block_idx][idx]; - new_demand.update(get_demand_before(ctx, block_idx, idx)); /* if reg pressure is too high, spill variable with furthest next use */ while ((new_demand - spilled_registers).exceeds(ctx.target_pressure)) {