In D48202 the helper function MergeBasicBlockIntoOnlyPred() was removed from llvm with the exception of JumpThreading. @asbirlea asked me to look at it for this final case. This patch replaces the last remaining usage of MergeBasicBlockIntoOnlyPred() with MergeBlockIntoPredecessor(). (I didn't fully remove the function and its test cases. I consider that work for a separate patch.)
This is a bit more complex than a simple function replacement for the following reasons:
- MergeBlockIntoPredecessor() may return false and not perform the merge while MergeBasicBlockIntoOnlyPred() always performed the action.
- The checks in MergeBlockIntoPredecessor() are slightly different.
- MergeBlockIntoPredecessor() does block hoisting. This was by far the biggest change and caused several re-labeling of blocks in test cases.
- In a few test cases the hoisting prevented existing checks from detecting trivially dead code from the existing logic in ProcessBlock.
- A bug in MergeBlockIntoPredecessor() causing DTU asserts, fixed with D58444.
Passes make-check on x86_64, test-suite on x86_64. I see nominal gains of a few percent overall on compile_time in test-suite and test-suite with CTmark. The benchmark execution times are on par, indicating this change (should be) a no-op for emitted IR.
Note: This diff relies on D58444 being comitted first. Without it test-suite benchmarks cause compiler asserts.
Finally, there is one instance in the test cases, lvi-after-jumpthreading.ll where hoisting causes the loss of valuable LVI information. There is no API to inform LVI two blocks have been merged other than deleting the merged block and (potentially) deleting the block that was merged into. It would be nice to have an LVI API similar to LVI->threadEdge(...) to prevent such metadata loss. Ideally it'd be a parameter to MergeBlockIntoPredecessor().