reko icon indicating copy to clipboard operation
reko copied to clipboard

Write after read anti-dependency not handled correctly in delay slots

Open uxmal opened this issue 4 years ago • 0 comments

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)

uxmal avatar Dec 11 '21 00:12 uxmal