From f91ac09f87c75abf4fdc5d48dd813c62a3d90bf1 Mon Sep 17 00:00:00 2001 From: Paulo Matos Date: Tue, 2 Dec 2025 15:26:14 +0100 Subject: [PATCH 1/2] Set current code block in x87 pass This resets the constant pool in IREmit used by SelectAddressMode(). Fixes #5084. --- FEXCore/Source/Interface/IR/Passes/x87StackOptimizationPass.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/FEXCore/Source/Interface/IR/Passes/x87StackOptimizationPass.cpp b/FEXCore/Source/Interface/IR/Passes/x87StackOptimizationPass.cpp index f903b225a..12649b6e0 100644 --- a/FEXCore/Source/Interface/IR/Passes/x87StackOptimizationPass.cpp +++ b/FEXCore/Source/Interface/IR/Passes/x87StackOptimizationPass.cpp @@ -733,6 +733,7 @@ void X87StackOptimization::Run(IREmitter* Emit) { // The optimization should run per-block Reset(); + IREmit->SetCurrentCodeBlock(BlockNode); for (auto [CodeNode, IROp] : CurrentIR.GetCode(BlockNode)) { if (!LoweredX87(IROp->Op)) { continue; From fc771c868383e9c12e7c0f59ac297c491ad9c85b Mon Sep 17 00:00:00 2001 From: Paulo Matos Date: Tue, 2 Dec 2025 08:24:18 +0100 Subject: [PATCH 2/2] asm_tests: Set current code block in x87 pass --- .../FEX_bugs/issue5084_crossblock_const.asm | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 unittests/ASM/FEX_bugs/issue5084_crossblock_const.asm diff --git a/unittests/ASM/FEX_bugs/issue5084_crossblock_const.asm b/unittests/ASM/FEX_bugs/issue5084_crossblock_const.asm new file mode 100644 index 000000000..8ba933fcf --- /dev/null +++ b/unittests/ASM/FEX_bugs/issue5084_crossblock_const.asm @@ -0,0 +1,31 @@ +%ifdef CONFIG +{ + "RegData": { + "RAX": "0x0" + } +} +%endif + +; Regression test for issue 5084 +; This test was mostly reverse engineered from the IR in 5084. +; Failed with '-n 500 -m' with the error message: +; %51: Arg[0] references invalid %24 + +mov rax, 0 +mov rbx, 0xe0000000 +mov rcx, 1 + +test rcx, rcx +jnz .late_target + +.fallthrough: +fld1 +fstp tword [rbx + 0x1234] +mov rax, 0 +hlt + +.late_target: +fld1 +fstp tword [rbx + 0x1234] +mov rax, 0 +hlt