reko
reko copied to clipboard
Write after read anti-dependency not handled correctly in delay slots
The Reko scanner reorders instructions in the delay slots of afflicted architectures (SPARC, MIPS, PARISC etc) so that the generated code appears closer to code that a human might write. In the following sample code, there is a write-after-read dependency on the register r4:
jalr r4
lw r4,20(r3)
Reko translates this by 'stealing' the lw instruction and placing it before the jalr instruction. This results in:
r4 = Mem0[r3 + 20<i32>
call r4 (0)
which is incorrect as r4 is trashed before the call instruction.
To fix this requires making sure that no WAR anti-dependency exists, and if it does, copy the required value of r4 into a temporary to avoid the problem:
v3 = r4
r4 = Mem0[r3 + 20<i32>
call v3 (0)