From 10be90671f3d01ca0e7162fdc3ebadc2e6f6094c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Sch=C3=BCrmann?= Date: Mon, 7 Oct 2019 02:32:54 +0200 Subject: [PATCH] aco: re-use existing phi instruction when lowering boolean phis Reviewed-by: Rhys Perry --- src/amd/compiler/aco_lower_bool_phis.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/amd/compiler/aco_lower_bool_phis.cpp b/src/amd/compiler/aco_lower_bool_phis.cpp index 8cfc0eee0cd..7a4940ab1c8 100644 --- a/src/amd/compiler/aco_lower_bool_phis.cpp +++ b/src/amd/compiler/aco_lower_bool_phis.cpp @@ -136,11 +136,12 @@ void insert_before_logical_end(Block *block, aco_ptr instr) block->instructions.insert(std::prev(it.base()), std::move(instr)); } -aco_ptr lower_divergent_bool_phi(Program *program, Block *block, aco_ptr& phi) +void lower_divergent_bool_phi(Program *program, Block *block, aco_ptr& phi) { Builder bld(program); ssa_state state; + state.latest[block->index] = phi->definitions[0].tempId(); for (unsigned i = 0; i < phi->operands.size(); i++) { Block *pred = &program->blocks[block->logical_preds[i]]; @@ -177,7 +178,20 @@ aco_ptr lower_divergent_bool_phi(Program *program, Block *block, ac } } - return bld.sop1(aco_opcode::s_mov_b64, phi->definitions[0], get_ssa(program, block->index, &state)).get_ptr(); + unsigned num_preds = block->linear_preds.size(); + if (phi->operands.size() != num_preds) { + Pseudo_instruction* new_phi{create_instruction(aco_opcode::p_linear_phi, Format::PSEUDO, num_preds, 1)}; + new_phi->definitions[0] = phi->definitions[0]; + phi.reset(new_phi); + } else { + phi->opcode = aco_opcode::p_linear_phi; + } + assert(phi->operands.size() == num_preds); + + for (unsigned i = 0; i < num_preds; i++) + phi->operands[i] = get_ssa(program, block->linear_preds[i], &state); + + return; } void lower_linear_bool_phi(Program *program, Block *block, aco_ptr& phi) @@ -213,7 +227,8 @@ void lower_bool_phis(Program* program) if (phi->opcode != aco_opcode::p_phi && phi->opcode != aco_opcode::p_linear_phi) break; if (phi->opcode == aco_opcode::p_phi && phi->definitions[0].regClass() == s2) { - non_phi.emplace_back(std::move(lower_divergent_bool_phi(program, &block, phi))); + lower_divergent_bool_phi(program, &block, phi); + block.instructions.emplace_back(std::move(phi)); } else if (phi->opcode == aco_opcode::p_linear_phi && phi->definitions[0].regClass() == s1) { /* if it's a valid non-boolean phi, this should be a no-op */ lower_linear_bool_phi(program, &block, phi); -- 2.30.2