This version should now be restricted to the fix for the liveness of LR.
This is a follow-up to this thread:
This patch has a few things packed together and is not really intended to be in the final form, but to demonstrate the approach for now.
The original issue was with the tail merging leaving inconsistent liveness information around. That is addressed in this patch by adding IMPLICIT_DEFs where needed. LivePhysRegs is used to determine whether something is a live-in to a block, and here's where the remaining 90% of this patch comes from:
On ARM, if MBB is a return block, LivePhysRegs will add LR to its live-ins, if LR is in CalleeSavedInfo. It does that for each register in CSI because the assumption is that if something is saved and restored, then it is live outside of the function. The problem with LR is that it is not restored (in many cases) and so it doesn't need to be treated as a live-out from the function, and subsequently as a live-in to the return block. In tail merging, having it as a live-in to a block caused IMPLICIT_DEFs defining LR to appear in some predecessors, which then prevented certain macro-fusion-like optimizations (merging cmp with a branch) from happening later on.
The approach to deal with it taken here is to add a field in CalleeSavedInfo indicating that the saved register is actually restored. It is set to "true" by default, and target's implementation of restoreCalleeSavedRegisters should only reset it to "false" when the register is not restored. Currently, this only applies to LR on ARM. This has the consequence that the CSI parameter is no longer "const", which is not something I'm a fan of. LivePhysRegs is the user of that information when it adds block live-outs.