id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	os	architecture	failure	difficulty	testcase	blockedby	blocking	related
3552	Unreachable code in optimised CMM code	simonpj		"Ben found that GHC is gnerating some unreachable C-- code.  While the NCG should handle that case, it's curious, so I'm recording it as a ticket to look at with the new codegen pipeline.

While working on the NCG I've come across this:
{{{
benl@mavericks:~/devel/ghc/ghc-head-incoming> inplace/bin/ghc-stage1 -c
rts/Updates.cmm -ddump-opt-cmm

==================== Optimised Cmm ====================
...
cp: _ch::I32 = I32[_cb::I32 + 4];
I32[_ch::I32] = _c6::I32;
I32[_cb::I32 + 4] = _ch::I32 + 4;
I32[_c6::I32 + 0] = stg_IND_OLDGEN_info;
jump (I32[Sp + 0]) ();
cq: goto cq;
}
}}}

The goto instruction at cq: is unreachable.


However, in nativeGen/RegAlloc/Linear/Main.hs we have:
{{{
{- from John Dias's patch 2008/10/16:
The linear-scan allocator sometimes allocates a block
before allocating one of its predecessors, which could lead to
inconsistent allocations. Make it so a block is only allocated
if a predecessor has set the ""incoming"" assignments for the block, or
if it's the procedure's entry block.

BL 2009/02: Careful. If the assignment for a block doesn't get set for
some reason then this function will loop. We should probably do some
more sanity checking to guard against this eventuality.
-}
}}}

I'm in a situation where the linear allocator is looping because it's
trying to wait for a predecessor of cq: to set the incoming register
assignments, but that never happens because it's unreachable.

I don't know why it wasn't looping until now, maybe because i've wibbled
some function and caused some previously undemanded computation to hit
this loop.

Do we want the allocator to accept the above code, or just panic? Is
this a bug in the Cmm code generator, or is there a good reason why
there is an unreachable loop in this code?
"	bug	closed	normal	7.2.1	Compiler	6.10.4	fixed		ezyang	Unknown/Multiple	Unknown/Multiple	None/Unknown	Unknown				
