Continuing the discussion from llvm-dev (http://lists.llvm.org/pipermail/llvm-dev/2019-September/135381.html), I am proposing a patch to address this problem.
Background: The SystemZ backend can optimize compare instructions if it can first find all the users of the CC (condition code).
This can only reasonably be done when all the CC users are in the same basic block (to avoid expensive searching), so the first step is to check if the CC register is live into any successor block (live out) or not.
This check is currently done in SystemZElimCompare.cpp, but it would be better to have a common code method for this with an explicit guarantee that this can be trusted.
This patch adds:
- New method MachineBasicBlock::isLiveOut() that checks the live-in lists of its successors, to replace SystemZElimCompare.cpp:isCCLiveOut(). The comment for it gives a guarantee that this register is not live out of the block if it returns false, while however there is no check for sub/super-registers.
- MachineVerifier::visitMachineFunctionAfter() extended to check the live-through case for live-in lists, with tests. This is (currently) only done for registers without aliases and that are neither allocatable or reserved, such as the SystemZ::CC register. My hope is that with this, live-in lists for SystemZ::CC is fully verified, as it adds the missing check for live-through. Currently the MachineVerifier only catches the case of a live-in use without an entry in the live-in list, as "using an undefined physical register".