To fix PR28014, this patch restricts tail merging to blocks that belong to the same loop after machine block placement (MBP). Otherwise, merging a loop block with a block not belonging to the same loop can change the loop header (and other loop properties) of the current loop, inner loop or outer loop. Instead of updating all the loop info (which can be difficult), i choose to prevent merging blocks in these cases because the layout of the loop is weird even if I updated the loop information.
MBP creates optimized layout which brings new opportunities for tail merging. If tail merging could significantly change the layout such as changing the loop header, then the reason to do tail merging after MBP is gone. Unprofitable tail merging could reduce the fallthrough opportunities and make the layout work harder when we call MBP again.
I checked SPEC2006 and this change makes very small impact.
This is tricky to parse. It would be clearer as:
Bail if merging after placement and IBB is the loop header.
Whether IBB is the loop header or not shouldn't be changed by placement.