mem2reg & reg2mem

I have a register allocation bug I'm trying to track down. It's caused by a
convoluted series of events that results in a massive amount of code,
so looking at asm diffs is rather unhelpful.

I came up with the bright idea of adding a MaxPromotes flag to limit
the number of candidates that mem2reg promotes. But I couldn't
figure out how to safely promote some candidates but not others.
At the end of the pass, llvm assumes it can just delete all allocas.

So I took plan B and added a MaxDemotes to the reg2mem pass and
ran it right before regalloc. I cranked it up to demote everything but
apparently there are still register allocation candidates left because
the resulting program still fails and the asm has spill and reload
instructions in it.

So I looked at reg2mem and it looks like it only demotes "escaping"
allocas.

Err, so this isn't really the opposite of mem2reg because according to
mem2reg there shouldn't be ANY allocas left after it runs.

So how can I limit the number of register candidates? Just mark some
number of them as spilled upon entry to regalloc? Is there a better way?

                                        -Dave