Ticket #1512 (closed bug: fixed)
NCG to handle cyclic fixups for rematching register assignment for jump blocks
|Reported by:||guest||Owned by:|
|Type of failure:||Difficulty:||Moderate (less than a day)|
|Test Case:||Blocked By:|
joinToTargets in RegisterAlloc.hs generates a jump to a particular target. On the first jump to a target, the virtual register assignment is associated with this target. All following jumps to the target must ensure that the current virtual register assignment matches that one of the target. If that's not the case, fixup code is generated before the branch instruction.
In rare cases, that occur when compiling the RTS on i386 in -fPIC -dynamic mode we have to generate cyclic fixup code. Here is one issue that comes from compiling PrimOps?.cmm:
Assignment of target:
- virtual register A in real register A
- virtual register B in real register B.
- virtual register A in real register B
- virtual register B in real register A.
Basically, we have to move A to B, and B to A. There is no move sequence that allows this without using a scratch register. RegisterAlloc.hs detects this by using stronglyConnCompR in joinToTargets (Line 869). At the moment, it does not provide a solution for this, it just fails.
My trivial approach would be:
handleComponent (CyclicSCC ((vreg,src,dsts):rest)) = let sccs = stronglyConnCompR rest in [makeMove vreg src (InMem empty_spill)] ++ concatMap handleComponent sccs ++ map (makeMove vreg (InMem empty_spill)) dsts
I'm only having trouble to find empty_spill, namely an empty spill slot on the stack. I have no clear idea what the (simulated) stack pointer is pointing at and whether it is save to assume that below (above?) is scratch space I can abuse for such a task.