Previously the CodeExtractor created exit stubs, and the subsequent return value of the outlined function based on the order of out-of-region blocks after splitting any phi nodes, and collecting the blocks to be outlined. This could cause differences in order if there was a difference of exit block phi nodes between the two regions. This patch moves the collection of the output target blocks to be before this occurs, so that the assignment of target block to output value will be the same, regardless of the contents of the output block.
Should there be an assert:
assert(NumExitBlocks < 0xffff && "too many exit blocks for switch");
or do you think that's too unlikely to matter?
Doesn't the switch need the same type as the cases, or am I misunderstanding what's going on here?
Code following this doesn't assign into the variable, so we may as well drop the & on this one for clarity.
I think it's pretty unlikely that there will ever by that many exits out of a function.
They do, but if there are only two exit blocks, there are only two options, a 0 and 1, returned out of the outlined function. If that's the case, the CodeExtractor simplifies this to a branch instruction anyway.
I think it would be good to assert anyway if it's possible that it will happen. In the event that it does, I'd prefer to debug an assert than a later crash.