From 3bed46b844726474e083e0cba22a13b57ac7b9f0 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sat, 6 Dec 2025 03:55:33 +0300 Subject: [PATCH] rsx/fp/cfg: Fix IF/ELSE and LOOP node linkage --- rpcs3/Emu/RSX/Program/Assembler/FPToCFG.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/RSX/Program/Assembler/FPToCFG.cpp b/rpcs3/Emu/RSX/Program/Assembler/FPToCFG.cpp index 7887a8a9f4..fbdf830cf7 100644 --- a/rpcs3/Emu/RSX/Program/Assembler/FPToCFG.cpp +++ b/rpcs3/Emu/RSX/Program/Assembler/FPToCFG.cpp @@ -1,5 +1,4 @@ #include "stdafx.h" - #include "CFG.h" #include "Emu/RSX/Common/simple_array.hpp" @@ -107,11 +106,25 @@ namespace rsx::assembler { case EdgeType::IF: case EdgeType::ELSE: - bb->insert_succ(*found, EdgeType::ENDIF); + { + // Find the merge node from the parent + auto parent = bb->pred.back().from; + auto succ = std::find_if(parent->succ.begin(), parent->succ.end(), FN(x.type == EdgeType::ENDIF)); + ensure(succ != parent->succ.end(), "CFG: Broken IF linkage. Please report to developers."); + bb->insert_succ(succ->to, EdgeType::ENDIF); + succ->to->insert_pred(bb, EdgeType::ENDIF); break; + } case EdgeType::LOOP: - bb->insert_succ(*found, EdgeType::ENDLOOP); + { + // Find the merge node from the parent + auto parent = bb->pred.back().from; + auto succ = std::find_if(parent->succ.begin(), parent->succ.end(), FN(x.type == EdgeType::ENDLOOP)); + ensure(succ != parent->succ.end(), "CFG: Broken LOOP linkage. Please report to developers."); + bb->insert_succ(succ->to, EdgeType::ENDLOOP); + succ->to->insert_pred(bb, EdgeType::ENDLOOP); break; + } default: // Missing an edge type? rsx_log.error("CFG: Unexpected block exit. Report to developers.");