diff --git a/src/amd/compiler/aco_live_var_analysis.cpp b/src/amd/compiler/aco_live_var_analysis.cpp index cb7b12e78f8..7eb58b19123 100644 --- a/src/amd/compiler/aco_live_var_analysis.cpp +++ b/src/amd/compiler/aco_live_var_analysis.cpp @@ -176,14 +176,13 @@ process_live_temps_per_block(Program* program, Block* block, unsigned& worklist, /* handle phi definitions */ uint16_t linear_phi_defs = 0; - int phi_idx = idx; - while (phi_idx >= 0) { + for (int phi_idx = 0; phi_idx <= idx; phi_idx++) { + register_demand[phi_idx] = new_demand; Instruction* insn = block->instructions[phi_idx].get(); assert(is_phi(insn) && insn->definitions.size() == 1); if (!insn->definitions[0].isTemp()) { assert(insn->definitions[0].isFixed() && insn->definitions[0].physReg() == exec); - phi_idx--; continue; } Definition& definition = insn->definitions[0]; @@ -194,17 +193,13 @@ process_live_temps_per_block(Program* program, Block* block, unsigned& worklist, if (n) { definition.setKill(false); + if (insn->opcode == aco_opcode::p_linear_phi) { + assert(definition.getTemp().type() == RegType::sgpr); + linear_phi_defs += definition.size(); + } } else { - new_demand += temp; definition.setKill(true); } - - if (insn->opcode == aco_opcode::p_linear_phi) { - assert(definition.getTemp().type() == RegType::sgpr); - linear_phi_defs += definition.size(); - } - - phi_idx--; } for (unsigned pred_idx : block->linear_preds) @@ -245,11 +240,12 @@ process_live_temps_per_block(Program* program, Block* block, unsigned& worklist, } /* handle phi operands */ - phi_idx = idx; - while (phi_idx >= 0) { - register_demand[phi_idx] = new_demand; + for (int phi_idx = 0; phi_idx <= idx; phi_idx++) { Instruction* insn = block->instructions[phi_idx].get(); assert(is_phi(insn)); + /* Ignore dead phis. */ + if (insn->definitions[0].isKill()) + continue; /* directly insert into the predecessors live-out set */ Block::edge_vec& preds = insn->opcode == aco_opcode::p_phi ? block->logical_preds : block->linear_preds; @@ -274,7 +270,6 @@ process_live_temps_per_block(Program* program, Block* block, unsigned& worklist, /* set if the operand is killed by this (or another) phi instruction */ operand.setKill(!live.count(operand.tempId())); } - phi_idx--; } block->live_in_demand = new_demand;