When there are multiple outgoing edges from outlined region to the return block, a new return block is created and the original return block becomes the 'pre-return block' to factor all incoming values from the outlined region to the new return. The original return block will be part of the outlined region. The original phi in the pre-return block is pruned so that it only takes incoming values from the outlined region.
There are cases when the old phi becomes trivial (all operands have the same value) -- for instance with the same constant or same live across value (from outside the region). In such cases, leaving the phi node will make the code-extractor decide that the phi's def is a live out value defined inside the outlined region -- this leads to additional runtime overhead: stack space to store the live out value, passing the address, in addition to load/store around the outlined calls.
This patch cleans it up.
Maybe a little bit simpler to use find_if, but I am not sure.