summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2021-04-22 23:33:49 +0200
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:29 +0200
commit25949b864c40405946d434ecc85d6c167f323a24 (patch)
tree3e7025cd196437b2090188b2ac9bbb765a891719
parentshader: Remove invalidated blocks in dead code elimination pass (diff)
downloadyuzu-25949b864c40405946d434ecc85d6c167f323a24.tar
yuzu-25949b864c40405946d434ecc85d6c167f323a24.tar.gz
yuzu-25949b864c40405946d434ecc85d6c167f323a24.tar.bz2
yuzu-25949b864c40405946d434ecc85d6c167f323a24.tar.lz
yuzu-25949b864c40405946d434ecc85d6c167f323a24.tar.xz
yuzu-25949b864c40405946d434ecc85d6c167f323a24.tar.zst
yuzu-25949b864c40405946d434ecc85d6c167f323a24.zip
-rw-r--r--src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp b/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
index 3bab742e7..a8064a5d0 100644
--- a/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
+++ b/src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
@@ -278,20 +278,22 @@ private:
}
same = op;
}
+ // Remove the phi node from the block, it will be reinserted
+ IR::Block::InstructionList& list{block->Instructions()};
+ list.erase(IR::Block::InstructionList::s_iterator_to(phi));
+
+ // Find the first non-phi instruction and use it as an insertion point
+ IR::Block::iterator reinsert_point{std::ranges::find_if_not(list, IsPhi)};
if (same.IsEmpty()) {
// The phi is unreachable or in the start block
- // First remove the phi node from the block, it will be reinserted
- IR::Block::InstructionList& list{block->Instructions()};
- list.erase(IR::Block::InstructionList::s_iterator_to(phi));
-
- // Insert an undef instruction after all phi nodes (to keep phi instructions on top)
- const auto first_not_phi{std::ranges::find_if_not(list, IsPhi)};
- same = IR::Value{&*block->PrependNewInst(first_not_phi, undef_opcode)};
-
- // Insert the phi node after the undef opcode, this will be replaced with an identity
- list.insert(first_not_phi, phi);
+ // Insert an undefined instruction and make it the phi node replacement
+ // The "phi" node reinsertion point is specified after this instruction
+ reinsert_point = block->PrependNewInst(reinsert_point, undef_opcode);
+ same = IR::Value{&*reinsert_point};
+ ++reinsert_point;
}
- // Reroute all uses of phi to same and remove phi
+ // Reinsert the phi node and reroute all its uses to the "same" value
+ list.insert(reinsert_point, phi);
phi.ReplaceUsesWith(same);
// TODO: Try to recursively remove all phi users, which might have become trivial
return same;