From b2cc625ac34f903a09aa8b5500769a5f54028c8b Mon Sep 17 00:00:00 2001 From: Matthew Schneider Date: Thu, 17 Sep 2026 12:48:00 -0400 Subject: [PATCH 1/4] Fix popping a temporary register that is shared with another slot --- src/engine/compiler/SinglePassCompiler.v3 | 1 + test/unittest/x86-64-linux/X86_64LinuxExeTest.v3 | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/engine/compiler/SinglePassCompiler.v3 b/src/engine/compiler/SinglePassCompiler.v3 index 0a45c4c13..eb83417ae 100644 --- a/src/engine/compiler/SinglePassCompiler.v3 +++ b/src/engine/compiler/SinglePassCompiler.v3 @@ -2716,6 +2716,7 @@ class SinglePassCompiler(xenv: SpcExecEnv, masm: MacroAssembler, regAlloc: RegAl } else { masm.emit_mov_r_s(kind, reg, state.sp); } + if (sv.reg != NO_REG) unrefLater(sv.reg, int.!(state.sp)); // the popped slot no longer uses it return SpcVal(sv.flags | IN_REG, reg, sv.const); } // Spill a register to its slot(s), if it has been allocated. diff --git a/test/unittest/x86-64-linux/X86_64LinuxExeTest.v3 b/test/unittest/x86-64-linux/X86_64LinuxExeTest.v3 index 259c4002d..4fd1b8204 100644 --- a/test/unittest/x86-64-linux/X86_64LinuxExeTest.v3 +++ b/test/unittest/x86-64-linux/X86_64LinuxExeTest.v3 @@ -16,7 +16,8 @@ component X86_64LinuxExeTest { ("load_oob0", test_load_oob0), ("call1005", test_call1005), // intended to trigger OSR ("osr_accessor", test_osr_accessor), - ("recompile_after_probe", test_recompile_after_probe) + ("recompile_after_probe", test_recompile_after_probe), + ("shared_reg_merge", test_shared_reg_merge) ]) { // register strategy/test pair UnitTests.registerT(strategy.0, test.0, newTester, test.1); @@ -61,6 +62,18 @@ def test_load_oob0(i: ExeTester) { i.args_i(0).assert2_trap(TrapReason.MEMORY_OOB); } +def test_shared_reg_merge(i: ExeTester) { + i.sig(SigCache.i_d).codev([ + u8.!(Opcode.BLOCK.code), BpTypeCode.F64.code, + u8.!(Opcode.LOCAL_GET.code), 0, + u8.!(Opcode.F64_CONVERT_I32_S.code), // pops a register the local still shares + u8.!(Opcode.LOCAL_GET.code), 0, + u8.!(Opcode.BR_IF.code), 0, // carries the converted value + u8.!(Opcode.END.code) + ]); + i.args_i(7).assert2_d(0x401C000000000000); // 7.0 +} + def test_call1005(i: ExeTester) { var f17 = byte.!(i.newFunction(SigCache.v_i, [u8.!(Opcode.I32_CONST.code), 17]).func_index); i.sig(SigCache.i_i); From b51f8c0b6944874865a98049a5d71d0d6a459a37 Mon Sep 17 00:00:00 2001 From: Matthew Schneider Date: Thu, 29 Oct 2026 00:57:39 -0400 Subject: [PATCH 2/4] Clean up test and fix --- src/engine/compiler/SinglePassCompiler.v3 | 2 +- test/unittest/x86-64-linux/X86_64LinuxExeTest.v3 | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/engine/compiler/SinglePassCompiler.v3 b/src/engine/compiler/SinglePassCompiler.v3 index eb83417ae..66d6e0c64 100644 --- a/src/engine/compiler/SinglePassCompiler.v3 +++ b/src/engine/compiler/SinglePassCompiler.v3 @@ -2713,10 +2713,10 @@ class SinglePassCompiler(xenv: SpcExecEnv, masm: MacroAssembler, regAlloc: RegAl masm.emit_mov_r_k(kind, reg, sv.const); } else if (sv.reg != NO_REG) { masm.emit_mov_r_r(kind, reg, sv.reg); + regAlloc.unassign(sv.reg, int.!(state.sp)); } else { masm.emit_mov_r_s(kind, reg, state.sp); } - if (sv.reg != NO_REG) unrefLater(sv.reg, int.!(state.sp)); // the popped slot no longer uses it return SpcVal(sv.flags | IN_REG, reg, sv.const); } // Spill a register to its slot(s), if it has been allocated. diff --git a/test/unittest/x86-64-linux/X86_64LinuxExeTest.v3 b/test/unittest/x86-64-linux/X86_64LinuxExeTest.v3 index 4fd1b8204..25befaa1f 100644 --- a/test/unittest/x86-64-linux/X86_64LinuxExeTest.v3 +++ b/test/unittest/x86-64-linux/X86_64LinuxExeTest.v3 @@ -67,8 +67,6 @@ def test_shared_reg_merge(i: ExeTester) { u8.!(Opcode.BLOCK.code), BpTypeCode.F64.code, u8.!(Opcode.LOCAL_GET.code), 0, u8.!(Opcode.F64_CONVERT_I32_S.code), // pops a register the local still shares - u8.!(Opcode.LOCAL_GET.code), 0, - u8.!(Opcode.BR_IF.code), 0, // carries the converted value u8.!(Opcode.END.code) ]); i.args_i(7).assert2_d(0x401C000000000000); // 7.0 From 6cb8835d4047dce76593afa835694d78dfb09f23 Mon Sep 17 00:00:00 2001 From: Matthew Schneider Date: Thu, 29 Oct 2026 15:23:44 -0400 Subject: [PATCH 3/4] Empty commit From a5784633375efa247654f77891b67d2de6cbda4e Mon Sep 17 00:00:00 2001 From: Matthew Schneider Date: Thu, 29 Oct 2026 17:20:03 -0400 Subject: [PATCH 4/4] Empty commit