Summary
SP1’s single-pass x86-64 JIT transpiler tracks compile-time constant register values during linear instruction emission and used them to emit unconditional direct jumps for jalr instructions.
When a jalr instruction was reachable via a control-flow edge that bypassed or overwrote the register value recorded linearly at compile time (for example, a branch skipping an intermediate auipc or a loop back-edge), the JIT unconditionally jumped to the stale static target instead of the runtime target PC, causing native x86-64 execution to diverge from RISC-V semantics.
Root Cause
- During single-pass x86-64 code generation, the transpiler cached compile-time register constants (such as
auipcoutputs) without invalidating them across incoming control-flow merges reaching ajalr. ControlFlowInstructions::jalrcomputed a staticjump_targetfrom that cached register value and passed it toTranspilerBackend::end_branch(jump_target).end_branchemitted an unconditional jump to the static label wheneverjump_targetresolved to a known PC, ignoring the runtime target PC computed intoCONTEXT + PC_OFFSET.
Remediation
Fixed in #3056 (e56c838): jalr retains the runtime target PC in RAX across clock/trace checks and calls a dedicated TranspilerBackend::end_jalr(jump_target) helper, which guards the direct-jump fast path with a runtime comparison (cmp rax, target_pc; je =>label, supporting both 32-bit sign-extended and wide 64-bit targets) and falls back to dynamic dispatch (self.jump_to_pc()) on mismatch.
