From a607ea51a76a9f5fd9b1f6467a16f494d23961c6 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Mon, 12 Aug 2019 20:40:37 +0200 Subject: [PATCH] aco: Cleanup insert_before_logical_end MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Daniel Schürmann Reviewed-by: Rhys Perry --- src/amd/compiler/aco_lower_bool_phis.cpp | 26 ++++++++++-------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/amd/compiler/aco_lower_bool_phis.cpp b/src/amd/compiler/aco_lower_bool_phis.cpp index 0c56ca07214..8cfc0eee0cd 100644 --- a/src/amd/compiler/aco_lower_bool_phis.cpp +++ b/src/amd/compiler/aco_lower_bool_phis.cpp @@ -29,6 +29,7 @@ #include "aco_ir.h" #include "aco_builder.h" +#include namespace aco { @@ -120,24 +121,19 @@ Temp write_ssa(Program *program, Block *block, ssa_state *state, unsigned previo return {id, s2}; } -void insert_before_branch(Block *block, aco_ptr instr) -{ - int end = block->instructions.size() - 1; - if (block->instructions[end]->format == Format::PSEUDO_BRANCH) - block->instructions.emplace(std::prev(block->instructions.end()), std::move(instr)); - else - block->instructions.emplace_back(std::move(instr)); -} - void insert_before_logical_end(Block *block, aco_ptr instr) { - for (int i = block->instructions.size() - 1; i >= 0; --i) { - if (block->instructions[i]->opcode == aco_opcode::p_logical_end) { - block->instructions.emplace(std::next(block->instructions.begin(), i), std::move(instr)); - return; - } + auto IsLogicalEnd = [] (const aco_ptr& instr) -> bool { + return instr->opcode == aco_opcode::p_logical_end; + }; + auto it = std::find_if(block->instructions.crbegin(), block->instructions.crend(), IsLogicalEnd); + + if (it == block->instructions.crend()) { + assert(block->instructions.back()->format == Format::PSEUDO_BRANCH); + block->instructions.insert(std::prev(block->instructions.end()), std::move(instr)); } - insert_before_branch(block, std::move(instr)); + else + block->instructions.insert(std::prev(it.base()), std::move(instr)); } aco_ptr lower_divergent_bool_phi(Program *program, Block *block, aco_ptr& phi) -- 2.30.2