From a771dc9b88972940cf21601e350a1fd99b86e1a5 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Tue, 22 Mar 2022 23:20:20 +0100 Subject: [PATCH] early-access version 2591 --- README.md | 2 +- .../ir_opt/dead_code_elimination_pass.cpp | 71 +++---------------- 2 files changed, 11 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 473979b51..0cd83e751 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 2590. +This is the source code for early-access 2591. ## Legal Notice diff --git a/src/shader_recompiler/ir_opt/dead_code_elimination_pass.cpp b/src/shader_recompiler/ir_opt/dead_code_elimination_pass.cpp index fe03b43ac..400836301 100755 --- a/src/shader_recompiler/ir_opt/dead_code_elimination_pass.cpp +++ b/src/shader_recompiler/ir_opt/dead_code_elimination_pass.cpp @@ -7,70 +7,19 @@ #include "shader_recompiler/ir_opt/passes.h" namespace Shader::Optimization { -namespace { -template -void DeadInstElimination(IR::Block* const block) { - // We iterate over the instructions in reverse order. - // This is because removing an instruction reduces the number of uses for earlier instructions. - auto it{block->end()}; - while (it != block->begin()) { - --it; - if constexpr (TEST_USES) { - if (it->HasUses() || it->MayHaveSideEffects()) { - continue; - } - } - it->Invalidate(); - it = block->Instructions().erase(it); - } -} - -void DeadBranchElimination(IR::Program& program) { - const auto begin_it{program.syntax_list.begin()}; - for (auto node_it = begin_it; node_it != program.syntax_list.end(); ++node_it) { - if (node_it->type != IR::AbstractSyntaxNode::Type::If) { - continue; - } - IR::Inst* const cond_ref{node_it->data.if_node.cond.Inst()}; - const IR::U1 cond{cond_ref->Arg(0)}; - if (!cond.IsImmediate()) { - continue; - } - if (cond.U1()) { - continue; - } - // False immediate condition. Remove condition ref, erase the entire branch. - cond_ref->Invalidate(); - // Account for nested if-statements within the if(false) branch - u32 nested_ifs{1u}; - while (node_it->type != IR::AbstractSyntaxNode::Type::EndIf || nested_ifs > 0) { - node_it = program.syntax_list.erase(node_it); - switch (node_it->type) { - case IR::AbstractSyntaxNode::Type::If: - ++nested_ifs; - break; - case IR::AbstractSyntaxNode::Type::EndIf: - --nested_ifs; - break; - case IR::AbstractSyntaxNode::Type::Block: { - IR::Block* const block{node_it->data.block}; - DeadInstElimination(block); - break; - } - default: - break; - } - } - // Erase EndIf node of the if(false) branch - node_it = program.syntax_list.erase(node_it); - } -} -} // namespace void DeadCodeEliminationPass(IR::Program& program) { - DeadBranchElimination(program); + // We iterate over the instructions in reverse order. + // This is because removing an instruction reduces the number of uses for earlier instructions. for (IR::Block* const block : program.post_order_blocks) { - DeadInstElimination(block); + auto it{block->end()}; + while (it != block->begin()) { + --it; + if (!it->HasUses() && !it->MayHaveSideEffects()) { + it->Invalidate(); + it = block->Instructions().erase(it); + } + } } }