id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	os	architecture	failure	difficulty	testcase	blockedby	blocking	related
1512	NCG to handle cyclic fixups for rematching register assignment for jump blocks	guest		"joinToTargets in [http://darcs.haskell.org/ghc/compiler/nativeGen/RegisterAlloc.hs 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.

Current assignment: 
 * 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. [http://darcs.haskell.org/ghc/compiler/nativeGen/RegisterAlloc.hs 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."	bug	closed	high	6.8.1	Compiler		fixed			Unknown/Multiple	Unknown/Multiple		Moderate (less than a day)				
